브랜치 정의
모든 버전 관리 시스템에는 브랜치(Branch)가 존재
나무에서 가지가 새 줄기를 뻗는 듯이 여러 갈래로 퍼지는 것
버전 관리를 시작하면 master라는 브랜치가 생성
커밋을 할 때마다 master브랜치는 최신 커밋을 가리킴
새 브랜치를 만들면(= 분기한다, branch)
기존에 저장한 파일은master브랜치에 그대로 유지하면서
기존 파일을 수정하거나 새로운 기능 추가가 가능
master브랜치에서 새 브랜치를 만드는 것
새 브랜치에 있던 파일을 원래 master브랜치에 합치는 것(=병합하다, merge)

$ mkdir manual
$ cd manual/
$ git init
Initialized empty Git repository in C:/Users/test/manual/.git/
$ ls -al
total 16
drwxr-xr-x 1 test 197609 0 4월 29 16:07 ./
drwxr-xr-x 1 test 197609 0 4월 29 16:07 ../
drwxr-xr-x 1 test 197609 0 4월 29 16:07 .git/
$ vi work.txt
contnet 1
$ git add work.txt
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
$ git commit -m "work 1"
[master (root-commit) 7cc51aa] work 1
1 file changed, 1 insertion(+)
create mode 100644 work.txt
$ git log
commit 7cc51aa0947c21c11d56b114aacb6fd49740c792 (HEAD -> master)
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:09:22 2020 +0900
work 1
git log를 확인하면 HEAD가 master브랜치를 가리킴
HEAD는 여러 브랜치 중에 현재 작업중인 브랜치를 가리킴
$ vi work.txt
content 1
content 2
$ git commit -am "work 2"
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
[master c0ab252] work 2
1 file changed, 1 insertion(+)
$ vi work.txt
content 1
content 2
content 3
$ git commit -am "work 3"
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
[master 5da07bb] work 3
1 file changed, 1 insertion(+)
$ git log
commit 5da07bb397ab74c33373d5468a6212c2d70e44a9 (HEAD -> master)
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:13:30 2020 +0900
work 3
commit c0ab2524d3af7d36c7f2c90029e738fce16743de
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:13:03 2020 +0900
work 2
commit 7cc51aa0947c21c11d56b114aacb6fd49740c792
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:09:22 2020 +0900
work 1
브랜치 만들기 : git branch 브랜치명
브랜치를 만들거나 확인하는 명령어
HEAD -> master : 현재 작업 중인 브랜치는 master
HEAD -> master, apple : 저장소에 master, apple 브랜치가 있으며 모두 work3이 최신 커밋.
$ git branch
* master
$ git branch apple
$ git branch
apple
* master #아직 master브랜치에서 작업 중
$ git log
commit 5da07bb397ab74c33373d5468a6212c2d70e44a9 (HEAD -> master, apple)
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:13:30 2020 +0900
work 3
commit c0ab2524d3af7d36c7f2c90029e738fce16743de
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:13:03 2020 +0900
work 2
commit 7cc51aa0947c21c11d56b114aacb6fd49740c792
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:09:22 2020 +0900
work 1
추가적으로 브랜치 생성하기
$ git branch google
$ git branch ms
$ git branch
apple
google
* master
ms
브랜치 사이 이동하기 : git checkout
-b 옵션을 사용하면 브랜치를 만들고 체크아웃을 진행
$ vi work.txt
content 1
content 2
content 3
master content 4
$ git commit -am "master content 4"
warning: LF will be replaced by CRLF in work.txt.
The file will have its original line endings in your working directory
[master 7af7aa5] master content 4
1 file changed, 1 insertion(+)
$ git log --oneline
7af7aa5 (HEAD -> master) master content 4 #현재 브랜치는 mater이며, master최신 커밋은 master content 4
5da07bb (ms, google, apple) work 3 #ms, google, apple 브랜치의 최신 커밋
c0ab252 work 2
7cc51aa work 1
$ git log
commit 7af7aa50920627064ff09259620e8e48c941c693 (HEAD -> master)
Author: unknown <계정명@github.com>
Date: Wed Apr 29 20:13:43 2020 +0900
master content 4
commit 5da07bb397ab74c33373d5468a6212c2d70e44a9 (ms, google, apple)
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:13:30 2020 +0900
work 3
commit c0ab2524d3af7d36c7f2c90029e738fce16743de
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:13:03 2020 +0900
work 2
commit 7cc51aa0947c21c11d56b114aacb6fd49740c792
Author: unknown <계정명@github.com>
Date: Wed Apr 29 16:09:22 2020 +0900
work 1
test@DESKTOP-E608UJK MINGW64 ~/manual (master) #현재 브랜치가 master
$ git checkout apple
Switched to branch 'apple'
test@DESKTOP-E608UJK MINGW64 ~/manual (apple) #현재 브랜치가 apple
$
$ git log --oneline
5da07bb (HEAD -> apple, ms, google) work 3
c0ab252 work 2
7cc51aa work 1
$ cat work.txt #apple이 master에서 분기된 이후에 master에 추가된 커밋은 apple에 영향이 없음
content 1
content 2
content 3
새 브랜치에서 커밋하기
--branches 옵션 : 각 브랜치의 커밋 확인 가능
--graph 옵션 : 그래프 형태로 확인 가능
$ vi work.txt
content 1
content 2
content 3
apple content 4
$ vi apple.txt
apple content 4
$ git add .
warning: LF will be replaced by CRLF in apple.txt.
The file will have its original line endings in your working directory
$ git commit -m "apple content 4"
[apple b86bf1c] apple content 4
2 files changed, 2 insertions(+)
create mode 100644 apple.txt
$ git log --oneline
b86bf1c (HEAD -> apple) apple content 4
5da07bb (ms, google) work 3
c0ab252 work 2
7cc51aa work 1
$ git log --oneline --branches
b86bf1c (HEAD -> apple) apple content 4
7af7aa5 (master) master content 4
5da07bb (ms, google) work 3
c0ab252 work 2
7cc51aa work 1
$ git log --oneline --branches --graph
* b86bf1c (HEAD -> apple) apple content 4
| * 7af7aa5 (master) master content 4
|/
* 5da07bb (ms, google) work 3
* c0ab252 work 2
* 7cc51aa work 1
브랜치 사이의 차이점 확인 : git log 기준브랜치..비교브랜치
브랜치 이름사이에 ..을 붙여 차이점 확인
브랜치 이름과 .(마침표)사이엔 공백이 없어야 함
$ git log master..apple
commit b86bf1ce1c345b8b61fb8bd6b117aad597d8bc46 (HEAD -> apple)
Author: unknown <계정명@github.com>
Date: Thu Apr 30 13:55:47 2020 +0900
apple content 4 #기준에 없는게 표시
$ git log apple..master
commit 7af7aa50920627064ff09259620e8e48c941c693 (master)
Author: unknown <계정명@github.com>
Date: Wed Apr 29 20:13:43 2020 +0900
master content 4 #기준에 없는게 표시
'git & github' 카테고리의 다른 글
원격 저장소와 깃허브 (0) | 2020.10.31 |
---|---|
브랜치 관리 (0) | 2020.10.31 |
브랜치 병합 (0) | 2020.10.31 |
Git으로 버전 관리하기 2 (0) | 2020.10.31 |
Git으로 버전 관리하기 1 (0) | 2020.10.31 |