Git

Git 다운로드

  1. 실습을 위해 작업 디렉토리를 생성
e:\>mkdir gitws         //관리자 권한으로 실행해야 mkdir이 가능

e:\>cd gitws        

git의 저장 과정

working directory에서

git add 를 하면

index 에 저장준비가 되고

git commit 을 하면

저장소에 실제로 저장이 된다.

  1. Git 사용을 위해 사용자 ID와 이메일을 입력.
git config --global user.name "내 이름"
git config --global user.email "내 이메일"

.git을 만들어서 git을 사용하기 위해

e:\>git init
  1. 파일관리를 시작

txt파일을 만들어서 관리해보자

title: "oasis-don'tlookbackinanger.txt"
author: "goaswon"
date: '2020 9 25'
output: html_document

sleep inside the eye of your mind.
don't you know you might find a better place to play.
you said that you never been,~~

git add를 하고 status로 체크

e:\gitws>dir
 E 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: 987D-79BE

 e:\gitws 디렉터리

2020-09-25  09:45    <DIR>          .
2020-09-25  09:45    <DIR>          ..
2020-09-25  09:45               238 oasis-don'tlookbackinanger.txt
               1개 파일                 238 바이트
               2개 디렉터리  519,417,352,192 바이트 남음

e:\gitws>git add "oasis-don'tlookbackinanger.txt"

e:\gitws>git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   oasis-don'tlookbackinanger.txt

아직 commit되지 않았다.

e:\gitws>git commit

을 하니 Vim창이 뜨며 commit comment를 적으라는 창이나온다 first commit이라고 적는다.

first commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
#
# Initial commit
#
# Changes to be committed:
#       new file:   oasis-don'tlookbackinanger.txt
#
E:/gitws/.git/COMMIT_EDITMSG[+] [unix] (10:33 25/09/2020)                                                       
1,12 All"E:/gitws/.git/COMMIT_EDITMSG" [converted][unix] 11L, 264C written

기존에 진행하던 방향에서 조금 다른 방식으로 진행하고싶어서 새로운 가지(branch)를 생성한다.

e:\gitws>git branch second
fatal: A branch named 'second' already exists.

second라는 branch를 생성했다.

e:\gitws>git status
On branch master
nothing to commit, working tree clean

현재 master branch에서 작업중이라고 나온다

e:\gitws>git checkout second
Switched to branch 'second'

second branch로 이동했다.

  ---
  title: "oasis-don'tlookbackinanger.txt"
  author: "goaswon"
  date: '2020 9 25'
  output: html_document
  ---
  sleep inside the eye of your mind.
  don't you know you might find a better place to play.
  you said that you never been, 
- but all the things that you've seen
- slowly fade away

두줄 추가

e:\gitws>git status
On branch second
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   oasis-don'tlookbackinanger.txt

no changes added to commit (use "git add" and/or "git commit -a")

modified: oasis-don'tlookbackinanger.txt가 빨간색으로 나오면서 변화가 있다고 알려줌. 또한 ’commit전에 add된 변화가 없다.’고 알려줌

e:\gitws>git commit -a -m 'second commit'
fatal: paths 'commit' ...' with -a does not make sense

-a는 add를 의미한다.

-m은 message를 뒤에 적는다는 것을 의미한다.

e:\gitws>git log -p
commit 6c4c4b1c1d1ade989b06f09ea01eaa130d5928f6 (HEAD -> second)
Author: goaswon <leechardfeynman@gmail.com>
Date:   Fri Sep 25 10:51:15 2020 +0900

    second commit

diff --git a/oasis-don'tlookbackinanger.txt b/oasis-don'tlookbackinanger.txt
index bd14f96..e15a085 100644
--- a/oasis-don'tlookbackinanger.txt
+++ b/oasis-don'tlookbackinanger.txt
@@ -6,4 +6,6 @@ output: html_document
 ---
 sleep inside the eye of your mind.
 don't you know you might find a better place to play.
-you said that you never been,~~
\ No newline at end of file
+you said that you never been,
+but all the things that you've seen
+slowly fade away
\ No newline at end of file

commit 853c37f32b23a48c942eeb2f117130421516a287 (master)
Author: goaswon <leechardfeynman@gmail.com>
Date:   Fri Sep 25 10:33:52 2020 +0900

    first commit

diff --git a/oasis-don'tlookbackinanger.txt b/oasis-don'tlookbackinanger.txt
new file mode 100644

git log -p를 통해 Commit별 차이점을 바로 볼 수 있다.

하지만 master branch에서는 second commit을 발견할 수 없다.

e:\gitws>git checkout master
Switched to branch 'master'

master로 옮겨옴

e:\gitws>git checkout master
Already on 'master'

e:\gitws>git log -p
commit 853c37f32b23a48c942eeb2f117130421516a287 (HEAD -> master)
Author: goaswon <leechardfeynman@gmail.com>
Date:   Fri Sep 25 10:33:52 2020 +0900

    first commit

diff --git a/oasis-don'tlookbackinanger.txt b/oasis-don'tlookbackinanger.txt
new file mode 100644
index 0000000..bd14f96
--- /dev/null
+++ b/oasis-don'tlookbackinanger.txt
@@ -0,0 +1,9 @@
+---
+title: "oasis-don'tlookbackinanger.txt"
+author: "goaswon "
+date: '2020 9 25'
+output: html_document
+---
+sleep inside the eye of your mind.
+don't you know you might find a better place to play.
+you said that you never been,~~
\ No newline at end of file

masterbranch를 secondbranch와 merge 한다.

그리고 master에서 git log -p를 확인해본다.

e:\gitws>git checkout master
Already on 'master'

e:\gitws>git merge second
Updating 853c37f..6c4c4b1
Fast-forward
 oasis-don'tlookbackinanger.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

e:\gitws>git log -p
commit 6c4c4b1c1d1ade989b06f09ea01eaa130d5928f6 (HEAD -> master, second)
Author: goaswon <leechardfeynman@gmail.com>
Date:   Fri Sep 25 10:51:15 2020 +0900

    second commit

diff --git a/oasis-don'tlookbackinanger.txt b/oasis-don'tlookbackinanger.txt
index bd14f96..e15a085 100644
--- a/oasis-don'tlookbackinanger.txt
+++ b/oasis-don'tlookbackinanger.txt
@@ -6,4 +6,6 @@ output: html_document
 ---
 sleep inside the eye of your mind.
 don't you know you might find a better place to play.
-you said that you never been,~~
\ No newline at end of file
+you said that you never been,
+but all the things that you've seen
+slowly fade away
\ No newline at end of file

commit 853c37f32b23a48c942eeb2f117130421516a287
Author: goaswon <leechardfeynman@gmail.com>
Date:   Fri Sep 25 10:33:52 2020 +0900

    first commit

diff --git a/oasis-don'tlookbackinanger.txt b/oasis-don'tlookbackinanger.txt
new file mode 100644

second commit과 변경점들이 나온다.

요약

  1. 디렉토리생성 git mkdir [만들 폴더명]

  2. git 초기화 git init

  3. 파일 생성 vim [만들려하는 파일명]

  4. 코드 작성

  5. working directory에 작성한 파일을 index에 추가 git add [파일명]

  6. 저장소에 내용을 add하고 commit git commit -m "메시지"

  7. second branch 생성 git branch second

  8. second branch로 변경 git checkout second

  9. [만든파일명] 파일에 내용을 추가 `vim [만든파일명]’후 수정

  10. working directory에 작성한 파일을 index에 추가 git add [만든파일명]

  11. 저장소에 내용을 제출하고 “second branch에 작업함”이라는 메세지로 저장
    git commit -m "second branch에 작업함"

  12. master branch로 변경하고 현재 디렉토리 파일 목록을 확인한다. git checkout master
    dir
    git log -p

  13. second branch로 이동해서 파일의 목록을 확인한다.
    git checkout second
    dir
    git log -p

  14. master branch로 이동해서 second branch를 병합한다.
    git checkout master
    git merge second
    git log -p