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 ์ฒดํ ๋!