Post

GIT branch ๊ณต๋ถ€

๐Ÿ“‹GIT branch

๋ฏธ๋ฆฌํ•ด์•ผํ•  ์ผ

git log --all --graph --oneline ๋ชจ๋“  branch๋“ค์„ ์‹œ๊ฐ์ ์œผ๋กœ, ํ•œ์ค„๋กœ ํ‘œํ˜„

git branch branch ๋ชฉ๋ก ๋ณด์—ฌ์ฃผ๊ธฐ

branch ์ •๋ฆฌ

git branch ๋ธŒ๋žœ์น˜์ด๋ฆ„ ํ˜„์žฌ ๋ฒ„์ „์œผ๋กœ ๋ธŒ๋žœ์น˜ ๋งŒ๋“ค๊ธฐ

git check out ๋ธŒ๋žœ์น˜์ด๋ฆ„ HEAD๊ฐ€ ํ•ด๋‹น ๋ธŒ๋žœ์น˜๋กœ ์ „ํ™˜ํ•˜๊ธฐ

โ•base : ํ•ฉ์น˜๋ ค๊ณ ํ•˜๋Š” ๋‘ ๋ธŒ๋žœ์น˜์˜ ๊ณตํ†ต๋œ ์กฐ์ƒ ๋ธŒ๋žœ์น˜

git merge ๋ธŒ๋žœ์น˜์ด๋ฆ„ ํ˜„์žฌ ๋ธŒ๋žœ์น˜์™€ ํ•ด๋‹น ๋ธŒ๋žœ์น˜ ๋ณ‘ํ•ฉํ•˜๊ธฐ

๊ฐ€์ƒ์˜ ํ”„๋กœ์ ํŠธ๋กœ ๊ฐ„๋‹จํ•˜๊ฒŒ branch ๋งŒ๋“ค์–ด๋ณด๊ธฐ

A. ์‹ค์Šต(?)์„ ์ง„ํ–‰ํ•  branch-study๋ผ๋Š” ๋””๋ ‰ํ† ๋ฆฌ ๋งŒ๋“ค๊ธฐ

1
2
3
4
parkjinhong@bagjinhong-ui-MacBookAir git % mkdir branch-study
parkjinhong@bagjinhong-ui-MacBookAir git % cd branch-study
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git init .
Initialized empty Git repository in /Users/parkjinhong/Documents/git/branch-study/.git/

B. main์˜ version1์„ commitํ•ด์ฃผ๊ณ  version2์™€ version3๋ฅผ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git add project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -m "main-version1"
[main (root-commit) f0e686c] main-version1
 1 file changed, 2 insertions(+)
 create mode 100644 project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git log
commit f0e686cb9cd71bbd2b9fa49ac2e541b76d1165bc (HEAD -> main)
Author: JiinHong <com5942@seoultech.ac.kr>
Date:   Tue Sep 19 23:34:45 2023 +0900

    main-version1
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % commit -am "main-verison2"
zsh: command not found: commit
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "main-version2"
[main dad6f68] main-version2
 1 file changed, 1 insertion(+)
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "main-version3"
[main cacd15b] main-version3
 1 file changed, 1 insertion(+)
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git log --all --graph --oneline
* cacd15b (HEAD -> main) main-version3
* dad6f68 main-version2
* f0e686c main-version1

C. main-version3์—์„œ branch 3๊ฐœ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ. branch์ด๋ฆ„์€ ๊ฐ๊ฐ naver, kakao, line.

1
2
3
4
5
6
7
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git branch naver
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git branch kakao
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git branch line
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git log --all --graph --oneline
* cacd15b (HEAD -> main, naver, line, kakao) main-version3
* dad6f68 main-version2
* f0e686c main-version1

D. main, naver, kakao, line ๊ฐ๊ฐ ์ƒˆ๋กœ์šด ๋ฒ„์ „ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "main-version4"
[main 2b20fd2] main-version4
 1 file changed, 1 insertion(+)
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git checkout naver
Switched to branch 'naver'
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "naver-version1"
[naver 7c4ae32] naver-version1
 1 file changed, 3 insertions(+)
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git checkout kakao
Switched to branch 'kakao'
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "kakao-version1"
[kakao e8e1179] kakao-version1
 1 file changed, 3 insertions(+)
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git checkout line
Switched to branch 'line'
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "line-version1"
[line 7cc4125] line-version1
 1 file changed, 3 insertions(+)
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git log --all --graph --oneline
* 7cc4125 (HEAD -> line) line-version1
| * e8e1179 (kakao) kakao-version1
|/  
| * 7c4ae32 (naver) naver-version1
|/  
| * 2b20fd2 (main) main-version4
|/  
* cacd15b main-version3
* dad6f68 main-version2
* f0e686c main-version1

๋‚˜๋ญ‡๊ฐ€์ง€๊ฐ€ ๋งŒ๋“ค์–ด์กŒ๋‹ค!

์ด์ œ merge ์‹œ๋„ํ•ด๋ณผ ์ฐจ๋ก€

(์ฐธ๊ณ )
main-version4์˜ ํ…์ŠคํŠธ๋Š”

1
2
3
4
5
main
version1
version2
version3
version4

naver-version1์˜ ํ…์ŠคํŠธ๋Š”

1
2
3
4
5
6
7
main
version1
version2
version3

naver
version1

commit๋  ๋•Œ๋งˆ๋‹ค ํ…์ŠคํŠธ์— ํ‘œ์‹œํ•ด๋†“๋Š” ๋ฐฉ์‹์œผ๋กœ ๋งŒ๋“ค์–ด์™”๋‹ค.

E. main-version4์™€ naver-version1์„ mergeํ•ด๋ณด๊ธฐ

1
2
3
4
5
6
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git checkout main
Switched to branch 'main'
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git merge naver
Auto-merging project.txt
CONFLICT (content): Merge conflict in project.txt
Automatic merge failed; fix conflicts and then commit the result.

Automatic merge failed ๋Š” merge๋ฅผ ์‹คํŒจํ–ˆ๋‹ค๋Š” ๋œป์ด ์•„๋‹ˆ๋ผ, merge๋Š” ์™„๋ฃŒ๋˜์—ˆ์œผ๋‚˜ project.txt๋ฅผ ์ž๋™์ ์œผ๋กœ ์ˆ˜์ •ํ•ด์ฃผ๋Š” ๊ฒƒ์„ ์‹คํŒจํ–ˆ๋‹ค๋Š” ๋œป์ด๋‹ค. ํ…์ŠคํŠธ์— ๋“ค์–ด๊ฐ€๋ณด๋ฉด,

1
2
3
4
5
6
7
8
9
10
11
main
version1
version2
version3
<<<<<<< HEAD
version4
=======

naver
version1
>>>>>>> naver

โ€™==โ€™๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‘ branch๊ฐ€ ์–ด๋–ป๊ฒŒ ์ถฉ๋Œ๋˜์–ด์žˆ๊ณ , ์‚ฌ์šฉ์ž์—๊ฒŒ ์–ด๋–ป๊ฒŒ ์ˆ˜์ •ํ• ์ง€ ๊ฒฐ์ •ํ•˜๋ผ๊ณ  ์นœ์ ˆํ•˜๊ฒŒ ํ‘œ์‹œํ•ด์ค€๋‹ค.

F. ์›ํ•ด๋Š”๋Œ€๋กœ ์ˆ˜์ •ํ•ด์ฃผ๊ณ  commit์„ ํ•ด์ฃผ๊ธฐ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
parkjinhong@bagjinhong-ui-MacBookAir branch-study % nano project.txt
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git commit -am "merge main-naver"
[main 6ec79cf] merge main-naver
parkjinhong@bagjinhong-ui-MacBookAir branch-study % git log --all --graph --oneline
*   6ec79cf (HEAD -> main) merge main-naver
|\  
| * 7c4ae32 (naver) naver-version1
* | 2b20fd2 main-version4
|/  
| * 7cc4125 (line) line-version1
|/  
| * e8e1179 (kakao) kakao-version1
|/  
* cacd15b main-version3
* dad6f68 main-version2
* f0e686c main-version1

branch์™€ merge ์ฒดํ—˜ ๋!

This post is licensed under CC BY 4.0 by the author.