728x90
๐ก ์ง๊ธ๊ป git init๋ถํฐ ๋ธ๋์น ๊ฐ์ merge๊น์ง ์๋ฐฑ ๋ฒ ๋๊ฒ ๊ฒฝํํ๋ฉด์ ๋จ ํ ๋ฒ๋ Git์ ๋ด๋ถ ๋์์ด๋ ์๋ฆฌ์ ๋ํด ๊ถ๊ธํจ์ ๊ฐ์ ธ๋ณธ ์ ์ด ์์์ต๋๋ค. ์ด๋ฒ ๊ธฐํ์ ๊ทธ ๋ด๋ถ๋ฅผ ์ ์ ์ด ์ดํด๋ณด๋ฉด์ Git์ ๋ํด ์ ๋๋ก ์ดํดํด๋ณด๋ ค๊ณ ํฉ๋๋ค.
๐ Git์ ์ผ๋ฐ์ ์ธ ์ฌ์ฉ๋ฒ ์ ๋๋ฅผ ์๊ณ ์์ด์ผ ํฉ๋๋ค.
๐ฅธ ์ ์ ์ง์
- Git ๋ด๋ถ์ ๋์ ๋ฐฉ์์ ์ดํดํ๊ธฐ ์ํด ํ์์ ์ผ๋ก ์์์ผ ํ ์ฉ์ด ๋ฐ ๊ฐ๋ ์ ๋๋ค.
- ์๋ ๋ด์ฉ์ ๊ฐ๋ณ๊ฒ ์ฝ์ด๋ณด์๊ณ , ์ค์ต ๋ถ๋ถ์์ ์ดํด๊ฐ ์๋์๋ฉด ๋์์ ํด๋น ๊ฐ๋ ์ ๋ค์ ์ฝ์ผ์๋ฉด ๋ณด๋ค ์์ํ๊ฒ ์ดํดํ์ค ์ ์์ผ๋ฆฌ๋ผ ์๊ฐ๋ฉ๋๋ค.
โ๐ป ์ฉ์ด ์ ๋ฆฌ
๐ธ HEAD
- Git์์ HEAD๋ ํ์ฌ ์์
์ค์ธ "๋ธ๋์น์ ๋ง์ง๋ง ์ปค๋ฐ์ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ"๋ฅผ ๋งํ๋ค.
- ๊ฐ์ฅ ์ต์ ์ปค๋ฐ์ ๊ฐ๋ฆฌํค๊ณ ์๋ ํฌ์ธํฐ์ธ ๊ฒ์ด๋ค.
๐ธ Git์ ์ ์ฅ ๋จ์ : Object
- Git์ ๋ด๋ถ์ ์ผ๋ก ๊ฐ์ฒด(Object)๋ผ๋ ์ด๋ฆ์ ์ ์ฅ ๋จ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ค.
- ์ด ๊ฐ์ฒด๋ค์ Git์ ๋ชจ๋ ๋์์ ๊ธฐ๋ฐ์ด ๋๋ฉฐ, ๋ฒ์ ๊ด๋ฆฌ๊ฐ ๊ฐ๋ฅํ ๊ตฌ์กฐ๋ฅผ ์ ๊ณตํ๋ค.
- Object์๋ blob, commit, tree, tag๊ฐ ์๋ค.
- ๋ชจ๋ ๊ฐ์ฒด๋ ๊ธฐ๋ณธ์ ์ผ๋ก SHA-1 ํด์๋ฅผ ์ฌ์ฉํ๋ค.
- Git 2.29 ์ด์์์๋ core.objectFormat=sha256 ์ค์ ์ ํตํด SHA-256์ ์ฌ์ฉํ ์ ์๋ค๊ณ ํ๋ค.
๐ Blob(Binary Large Object)
- git add ๋ช
๋ น์ด๋ฅผ ํตํด ์ถ๊ฐ๋๋ ๊ฐ์ฒด์ด๋ค.
- git add ์ blob ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ค.
- git add๋ก ์ถ๊ฐ๋ ๊ฐ๋ณ ํ์ผ์ ๋ด์ฉ๋ง ์ ์ฅํ๋ ๊ฐ์ฒด์ด๋ค.
- ํ์ผ ์ด๋ฆ์ด๋ ์์น ์ ๋ณด๋ ์๊ณ ์ค์ง ๋ด์ฉ๋ง์ ๋ด๋๋ค.
- ๋์ผํ ๋ด์ฉ์ด๋ฉด ์ธ์ ๋ ๋์ผํ SHA-1 ํด์๊ฐ์ ๊ฐ์ง๋ฏ๋ก ์ค๋ณต ์ ์ฅ์ด ๋์ง ์์ ๊ณต๊ฐ์ ์ ์ฝํ๋ค.
- ํ์ผ์ด ์์ ๋์ง ์์๋ค๋ฉด ์ปค๋ฐ์ ์ฌ๋ฌ ๋ฒ ํด๋ ๋์ผํ blob์ด ์ฌ์ฌ์ฉ๋๋ค.
๐ Commit
- commit์ Git์์ ํ๋์ ์ค๋ ์ท(๋ฒ์ )์ ์๋ฏธํ๋ฉฐ, ์ด๋ ํ๋ก์ ํธ์ ํน์ ์์ ์ ๊ฐ๋ฆฌํจ๋ค.
- git commit ๋ช
๋ น์ด๋ฅผ ํตํด ์ถ๊ฐ๋๋ ๊ฐ์ฒด์ด๋ค.
- ๋ง๊ทธ๋๋ก git commit์ ํตํด ์ ์ฅ๋ ์ค๋ ์ท(๋ฒ์ )์ ์ ์ฅํ๋ ๊ฐ์ฒด์ธ ๊ฒ์ด๋ค.
- ํ๋์ commit ๊ฐ์ฒด๋ ํ๋์ tree ๊ฐ์ฒด(ํ์ผ ๊ตฌ์กฐ ์ ์ฒด)๋ฅผ ๊ฐ๋ฆฌํจ๋ค.
- ๋ค์๊ณผ ๊ฐ์ ๋ฉํ๋ฐ์ดํฐ๋ฅผ ํฌํจํ๋ค.
- tree ํด์๊ฐ
- ๋ถ๋ชจ ์ปค๋ฐ ํด์๊ฐ(parent๋ก ํ์๋๋ฉฐ, ์ฒซ ์ปค๋ฐ์ด๋ผ๋ฉด ๋น์ฐํ๊ฒ๋ ์กด์ฌํ์ง ์๋๋ค.)
- ์์ฑ์(author) / ์ปค๋ฐํฐ(committer)
- ์ปค๋ฐ ๋ฉ์์ง
๐ Tree
- git commit ๋ช
๋ น์ด๋ฅผ ํตํด ์ถ๊ฐ๋๋ ๊ฐ์ฒด์ด๋ค.
- ์์์ ์ค๋ช ํ๋ฏ์ด Git์์ commit์ ํ๋ค๋ ๊ฑด ํด๋น ์์ ์ ์ค๋ ์ท(๋ฒ์ )์ ์ ์ฅํ๋ค๋ ๋ป์ด๋ค.
- tree๋ commit ์์ ํน์ ์์ ์ ๋ํ ๋๋ ํฐ๋ฆฌ(ํด๋) ๊ตฌ์กฐ์ ๊ทธ ์์ ํ์ผ๋ค์ ๋ํ๋ด๋ ๊ฐ์ฒด์ด๋ค.
- ์ด ๊ฐ์ฒด๋ ํด๋น ๋๋ ํฐ๋ฆฌ์ ํฌํจ๋ ํ์ผ๊ณผ ํ์ ๋๋ ํฐ๋ฆฌ(tree ๋๋ blob ๊ฐ์ฒด๋ค)์ ๋ชฉ๋ก์ ํธ๋ํนํ๊ณ , ๊ฐ๊ฐ์ ์ด๋ฆ, ๊ถํ, ๊ทธ๋ฆฌ๊ณ ํด๋น ๊ฐ์ฒด์ ํด์๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
- ์ข ๋ ์ ํํ ์ค๋ช
ํ๋ฉด ํด๋น ๋๋ ํฐ๋ฆฌ ๋ด์ ํ์ผ ๋ชฉ๋ก, ์ด๋ฆ, ๊ถํ(100644, 100755), ํ์
(blob/tree), ํด์๊ฐ(blob ๋๋ tree์ SHA-1 ํด์)์ ๊ฐ์ง๋ค.
- ๊ถํ์ด๋?
- ๊ถํ์์ 6์๋ฆฌ ์ซ์๋ ํ์ผ์ ๋ชจ๋๋ฅผ ์๋ฏธํ๋ค.
- ex) 100644์์ ์์ ๋ ์๋ฆฌ๋ ํ์ผ์ ํ์
์ด๋ค.
- 10์ ์ผ๋ฐ ํ์ผ, 12๋ ์ฌ๋ณผ๋ฆญ ๋งํฌ, 04๋ ๋๋ ํฐ๋ฆฌ์ด๋ค.
- ๋ค ๋ค์๋ฆฌ๋ ๊ถํ ๋นํธ(8์ง์)๋ฅผ ์๋ฏธํ๋ค.
- ๊ถํ์ด๋?
- ํ๋ง๋๋ก ์ ๋ฆฌํ๋ฉด, tree ๊ฐ์ฒด๋ commit ์์ ํน์ ์์ ์ ๋ํ blob ๊ฐ์ฒด(ํ์ผ)๋ ๋ค๋ฅธ tree ๊ฐ์ฒด(ํ์ ํด๋)๋ฅผ ํฌํจํ๋ค.
๐ Tag
- ํน์ commit์ ์ด๋ฆํ(label) ๋ฅผ ๋ถ์ด๋ ์ญํ ์ ํ๋ค.
- git tag๋ก ์์ฑํ๋ค.
- ๋ฒ์ ์ ๋ช
ํํ๊ฒ ๊ตฌ๋ถํ๊ณ , ๋ฆด๋ฆฌ์ค๋ฅผ ํ์ํ ๋ ์์ฃผ ์ฌ์ฉ๋๋ค.
- Lightweight tag : ๋จ์ํ ์ปค๋ฐ์ ํด์๋ฅผ ๊ฐ๋ฆฌํค๋ ํฌ์ธํฐ์ด๋ฉฐ ๊ฐ์ฒด๋ ์๋๋ค.
- Annotated tag : ๋ฉ์์ง, ์์ฑ์ ์ ๋ณด๋ฅผ ํฌํจํ๋ฉฐ ๋ณ๋์ ๊ฐ์ฒด๋ก ์ ์ฅ๋๋ค.
๐ Git ๋ด๋ถ ๊ตฌ์กฐ ํ๋์ ๋ณด๊ธฐ
HEAD
โโโถ Commit
โโโถ Tree
โ โโโถ Blob (hello.txt)
โ โโโถ Tree (src/) โโถ Blob (main.java)
โโโถ Parent Commit (์ด์ ์ค๋
์ท)
- ์์ Git ๊ฐ์ฒด์ ๋ํ ์ค๋ช
์ ํ ๋๋ก Git ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ํ๋์ฉ ๋ค์ ์ดํด๋ณด์.
- ์ด ์์๋ ์ปค๋ฐ์ด ์ฌ๋ฌ ๋ฒ ์ผ์ด๋ ํน์ ๋ธ๋์น์ ๋ด๋ถ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ธ ๊ฒ์ด๋ค.
- Head๋ ํ์ฌ ๋ธ๋์น์ ๋ง์ง๋ง(๊ฐ์ฅ ์ต์ ) commit์ ๊ฐ๋ฆฌํค๊ณ ์๋ค.
- ํ๋์ comitt ๊ฐ์ฒด์๋ ํ๋์ tree ๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
- ํ๋์ tree ๊ฐ์ฒด๋ Git์ ์ํด Commitํ ์์ ์์์ ํ์ ๋๋ ํฐ๋ฆฌ๋, ๊ฐ๋ณ ํ์ผ์ ์ ์ฅํ๋ค.
- Head๊ฐ ๊ฐ๋ฆฌํค๋ commit ๊ฐ์ฒด๊ฐ ์ต์ด์ commit์ด ์๋ ๊ฒฝ์ฐ, parent commit(๋ถ๋ชจ ์ปค๋ฐ ๊ฐ์ฒด)๋ฅผ ๊ฐ์ง๊ณ ์๋ค.
- ์ฆ, ํ๋์ commit์ ๋ถ๋ชจ commit(๋ฐ๋ก ์ง์ ์ commit)์ ๊ฐ์ง๊ณ ์๊ธฐ ๋๋ฌธ์ ์ปค๋ฐ ์ทจ์์ ๊ฐ์ ๋กค๋ฐฑ์ด ๊ฐ๋ฅํ ๊ฒ์ด๋ค.
๐ Git์ ์ธ ๊ฐ์ง ์ฃผ์ ์์ญ
๊ตฌ๋ถ | ์ค๋ช | ํ์ธ ์์น |
Working Directory | Git์์ ์์ ์ค์ธ ๋ก์ปฌ ํด๋๋ฅผ ๋งํ๋ค.(ํด๋, ํ์ผ ๋ฑ) | ํ๋ก์ ํธ ๋ฃจํธ ํด๋ |
Staging Area(Index) | ์ปค๋ฐํ ์ค๋น๊ฐ ๋ ํ์ผ๋ค์ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๊ณณ์ด๋ค. | .git/index |
Repository(Git Directory) | Git์ ๊ฐ์ฒด๊ฐ ์ ์ฅ๋๋ ๊ณณ์ด๋ค. | .git/objects |
๐ธ Git state ๋ช ์นญ๊ณผ ์ค๋ช
๐ Untracked
- Git์ด ์์ง ์ถ์ ํ์ง ์๋ ์ ํ์ผ์ ์๋ฏธํ๋ค.
- git add ๋ช ๋ น์ด๋ฅผ ์ด์ฉํ์ฌ Git์ด ํด๋น ํ์ผ์ ์ถ์ (๊ด๋ฆฌ)ํ๋๋ก ์ค๋น ์ํ๋ก ๋ง๋ค ์ ์๋ค.
- ํ ๋ฒ ์ถ์ ๋๊ธฐ ์์ํ๋ฉด unmodified๋ modified์ ๊ฐ์ด ํธ๋ํน ๋๋ฉด์ ๋ณ๊ฒฝ ๊ฐ์ง๊ฐ ๋๋ ๊ฒ์ด๋ค.
โ๏ธ Unmodified
- ์ด๋ฏธ Tracked ๋๊ณ ์๋ ์ํ์ด๋ค.(์ด๋ฏธ Git์ด ๊ด๋ฆฌํ๊ณ ์๋ ํ์ผ)
- Working Directory์ ํ์ผ์ด ๋ง์ง๋ง(๊ฐ์ฅ ์ต์ ) ์ปค๋ฐ๊ณผ ๋์ผํ๋ค๋ ์๋ฏธ๋ก, ํ์ผ์ด ๋ณ๊ฒฝ๋์ง ์์์์ ์๋ฏธํ๋ค.
- ๋ด๋ถ์ ์ผ๋ก๋ Working Directory ๋ด ํ์ผ์ ํด์๊ฐ๊ณผ, HEAD commit์ blob ํด์๊ฐ์ด ๋์ผํ๋ค๋ ๋ป์ด๋ค.
โ๏ธ Modified
- ์ด๋ฏธ Tracked ๋๊ณ ์๋ ์ํ์ด๋ค.(์ด๋ฏธ Git์ด ๊ด๋ฆฌํ๊ณ ์๋ ํ์ผ)
- unmodified์์ ์ฐจ์ด์ ์ ๊ธฐ์กด ํ์ผ๊ณผ์ ๋ณ๊ฒฝ ์ฌ๋ถ์ด๋ค.
- ์ถ์ ์ค์ธ ํ์ผ์ด ๋ณ๊ฒฝ๋์์์ Git์ด ์ธ์งํ๊ณ ์๋ ๊ฒ์ด๋ค.
- ์์ง staging area์๋ ์ฌ๋ฆฌ์ง ์์ ์ํ์ด๋ค.
- ๋ด๋ถ์ ์ผ๋ก๋ Working Directory ๋ด ๋ณ๊ฒฝ๋ ํ์ผ์ ํด์๊ฐ๊ณผ, HEAD commit์ blob ํด์๊ฐ์ด ๋ค๋ฅด๋ค๋ ๋ป์ด๋ค.
๐ Staged
- ๋ณ๊ฒฝ๋ ํ์ผ์ git add ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ staging area์ ์ฌ๋ฆด ์ ์๋ค.
- ๋ค์ ์ปค๋ฐ์ ํฌํจ๋ ์ค๋น๊ฐ ๋ ์ํ์ด๋ค.
- ๋ด๋ถ์ ์ผ๋ก๋ .git/index์ ๋ณ๊ฒฝ๋ ํ์ผ์ blob ๊ฐ์ฒด๊ฐ ์๋ก ์ ์ฅ๋๋ค.
๐ Committed
- staging area์ ๋ด์ฉ์ด ์ค์ ๋ก ์ปค๋ฐ๋ ์ํ์ด๋ค.
- Git์ด ์์ ํ ์ถ์ ํ๋ค๋ ์๋ฏธ์ด๋ค.
- ๋ด๋ถ์ ์ผ๋ก๋ .git/objects์ Tree ๊ฐ์ฒด์ Commit ๊ฐ์ฒด๊ฐ ์๋ก ์ ์ฅ๋๋ค.
- tree ๊ฐ์ฒด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ ์๋ก์ด Commit ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ ๊ฒ์ด๋ค.
๐จ ๊ทธ๋ฆผ์ผ๋ก Git state์ Git ๋ด๋ถ ๋ณํ ์ดํดํ๊ธฐ
- git ๋ช ๋ น์ด์ ์ํด ๊ฐ์ฒด๊ฐ ๋ฌผ๋ฆฌ์ ์ผ๋ก ์์ฑ๋๋ฉฐ, ์ด๋ .git ํด๋ ๋ด์์ ์ผ์ด๋๋ค.
- Working Directory๋ Git์ด ๊ด๋ฆฌํ๋ ๋ก์ปฌ ์์คํ
์์ ์ค์ ํ์ผ ๊ฒฝ๋ก๋ฅผ ์๋ฏธํ๋ค.
- ์ฌ์ฉ์๊ฐ Git์ ์ํด ๊ด๋ฆฌ๋๋ ํ์ผ์ ํธ์ง, ์์ฑ, ์ญ์ ํ๋ ๊ณต๊ฐ์ด๋ค.
- Staging Area๋ .git/index์, Git Repository๋ .git/object ๋ด๋ถ์ ๊ฐ์ฒด๋ก ๊ธฐ๋ก๋๋ค.
๐ธ ์๋ก ๋ง๋ ํ์ผ: Untracked -> Staged -> Committed
- ์ฒ์ ํ์ผ์ ์์ฑํ๋ฉด Git์ ์ด ํ์ผ์ ์กด์ฌ๋ง์ ๊ฐ์งํ ๋ฟ์ด๋ค. ์ด๋ ํ ๋ณ๊ฒฝ ์ฌํญ ๋ฑ์ ์ถ์ ์ ์งํํ์ง ์๋๋ค. ์ด๊ฒ์ด Untracked ์ํ์ด๋ค.
- git add๋ฅผ ํ๊ฒ ๋๋ฉด Staging area๋ก ๋ค์ด๊ฐ Git์ ์ถ์ ์ ๋ฐ์ ์ค๋น๋ฅผ ํ๊ฒ ๋๋ค.
- ์ด๋, ํด๋น ํ์ผ์ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก blob ๊ฐ์ฒด๊ฐ ์์ฑ๋์ด .git/objects/์ ์ ์ฅ๋๋ค.
- ์ด๋ฏธ ๋์ผํ ๋ด์ฉ์ด ์๋ ๊ฒฝ์ฐ๋ ์ฌ์ฌ์ฉํ๋ค.
- ๋ํ, .git/index์ ์๋ ์คํ ์ด์ง ์์ญ ์ ๋ณด์ ์ ์ฅ๋๋ค.
- ์ด๋, ํด๋น ํ์ผ์ ๋ด์ฉ์ ๊ธฐ๋ฐ์ผ๋ก blob ๊ฐ์ฒด๊ฐ ์์ฑ๋์ด .git/objects/์ ์ ์ฅ๋๋ค.
- ์ดํ commit์ ํ๊ฒ ๋๋ฉด Git์ ์ํด ๊ฐ์ฒด๋ก์ ์ถ์ ๋ฐ ๊ด๋ฆฌ๊ฐ ๋๊ธฐ ์์ํ๋ค.
- ์ด๋, ํด๋น ํ์ผ์ tree ๊ฐ์ฒด์ commit ๊ฐ์ฒด๊ฐ .git/objects/์ ์์ฑ๋๋ค.
๐ธ ๊ธฐ์กด ํ์ผ ์์ : (Unmodified → Modified) → Staged → Committed
- ๊ธฐ์กด ํ์ผ์ ์ด๋ฏธ Git์ ์ํด ์ถ์ ๋์ด์ง๊ณ ์๋ค. ๋ฐ๋ผ์ Git์ ํด๋น ํ์ผ์ด ์์ ๋์๋์ง ์๋์ง๋ฅผ ํญ์ ์ฒดํฌํ๋ค.
- ํ์ผ์ด ์์ ๋๋ฉด Unmodified์์ modified๋ก ์ํ๊ฐ ๋ณ๊ฒฝ๋๋ค.
- Git์ด ๋ณ๊ฒฝ ๊ฐ์ง๋ฅผ ํ ๊ฒ์ด๋ค.
- ์ดํ git add๋ฅผ ํ๊ฒ ๋๋ฉด Staging area๋ก ์ด๋ํ์ฌ ๋ค์ ์ปค๋ฐ์ ์ค๋นํ๊ฒ ๋๋ค.
- ์ด ๊ณผ์ ์์ ํด๋น ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฐ์๋ ์ blob ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ค.
- ์ด๋ฏธ ๋์ผํ ๋ด์ฉ์ด ์๋ ๊ฒฝ์ฐ๋ ์ฌ์ฌ์ฉํ๋ค.
- ์ด ๊ณผ์ ์์ ํด๋น ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฐ์๋ ์ blob ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ค.
- ์ดํ commit์ ํ๊ฒ ๋๋ฉด Git์ ์ด ํ์ผ์ ์ ์์ผ๋ก ์ ์ฅ์์ ๊ธฐ๋กํ๋ค.
- ์ด๋, ํด๋น ๋ณ๊ฒฝ ์ฌํญ์ด ๋ฐ์๋ ์ tree๊ณผ commit ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ค.
๐คง ๊ด๋ จ ๋ช ๋ น์ด
# ์คํ
์ด์ง ์์ญ ์ ๋ณด ํ์ธ
$ git ls-files --stage
# ํ์ฌ ์ปค๋ฐ ํด์ ํ์ธ
$ git rev-parse HEAD
# ๊ฐ์ฒด ํ์
ํ์ธ
$ git cat-file -t <ํด์>
# ๊ฐ์ฒด ๋ด์ฉ ๋ณด๊ธฐ
$ git cat-file -p <ํด์>
# tree ๋ด๋ถ ๊ตฌ์กฐ ๋ณด๊ธฐ
$ git ls-tree <treeํด์>
- ์๋ ์ค์ต ๋ ์ฌ์ฉํ ๋ช ๋ น์ด์ด๋ค.
- Git์ ๋ด๋ถ ๊ฐ์ฒด๋ ๋ฐ์ด๋๋ฆฌ ๋ฐ์ดํฐ๋ก ์ ์ฅ๋๊ธฐ ๋๋ฌธ์ ์ฝ์ ์ ์๊ฒ ๋ณ๋์ ๋ช ๋ น์ด๋ฅผ ํตํด ๋ณํํด์ผ ํ๋ค.
๐จ๐ป๐ฌ init๋ถํฐ merge๊น์ง Git์ ๋ด๋ถ์ ๋ณํ ์ดํด๋ณด๊ธฐ
# 1 ๋จ๊ณ: Commit ํด๋ณด๊ธฐ
git init
git add
git commit
# 2 ๋จ๊ณ: ๋ธ๋์น๋ฅผ ๋๋๊ณ merge ํด๋ณด๊ธฐ
git checkout -b feature/test1
git merge
- ์ ์ ์ ์ง์ ๋ด์ฉ์ ์ด๋์ ๋ ์ดํดํ ์ํ์์ ์ ๋ช ๋ น์ด๋ฅผ ์ด์ฉํด Git ๋ด๋ถ์ ๋ณํ๋ฅผ ์์ธํ ์ดํด๋ณด์.
โ๐ป 1 ๋จ๊ณ: Commit ํด๋ณด๊ธฐ
๐๏ธ ์ํ์ค ๋ค์ด์ด๊ทธ๋จ์ผ๋ก ์ดํด๋ณด๊ธฐ(init -> commit)
- ํ๋ฆ ์์ผ๋ก ๊ทธ๋ ค๋ณด์๋ค.
- ํฌ๊ฒ ์ ํ์ผ ์์ฑ๊ณผ ๊ธฐ์กด ํ์ผ ๋ณ๊ฒฝ์ ๊ธฐ์ค์ผ๋ก ๊ทธ๋ ธ๋ค.
- ์์ธํ ์ค๋ช ์ ์๋๋ฅผ ์ฐธ๊ณ ํ์.
๐๐ป git init
$ mkdir git-internal-test
$ cd git-internal-test
$ ls -al
# ์ถ๋ ฅ(git ์์ฑ ์ )
total 0
drwxr-xr-x 2 root staff 64 4 26 02:07 .
drwxr-xr-x 8 root staff 256 4 26 02:07 ..
$ git init
# ์ถ๋ ฅ(git ์์ฑ ํ)
Initialized empty Git repository in /๊ฒฝ๋ก/git-internal-test/.git/
$ ls -al
total 0
drwxr-xr-x 3 root staff 96 4 26 02:07 .
drwxr-xr-x 8 root staff 256 4 26 02:07 ..
drwxr-xr-x 9 root staff 288 4 26 02:07 .git
- git init ๋ช ๋ น์ด ์คํ ์ ํด๋น ๋ฃจํธ ํด๋์ .git ํด๋๊ฐ ์์ฑ๋๋ค.
- ์ด์ ํด๋น ํด๋๋ working directory๊ฐ ๋๋ฉฐ Git์ ์ํด ๊ด๋ฆฌ๋๋ค.
๐ .git ํด๋ ๋ด๋ถ ์์ธํ ์ดํด๋ณด๊ธฐ
/.git$ ll
# ์ถ๋ ฅ
total 24
-rw-r--r-- 1 root staff 137 4 26 02:07 config
-rw-r--r-- 1 root staff 73 4 26 02:07 description
-rw-r--r-- 1 root staff 21 4 26 02:07 HEAD
drwxr-xr-x 15 root staff 480 4 26 02:07 hooks
drwxr-xr-x 3 root staff 96 4 26 02:07 info
drwxr-xr-x 4 root staff 128 4 26 02:07 objects
drwxr-xr-x 4 root staff 128 4 26 02:07 refs
- .git ๋ด๋ถ์๋ ๊ฝค๋ ๋ง์ ํ์ผ๊ณผ ํด๋๊ฐ ์กด์ฌํ๋ค. ํ๋ํ๋ ๋ค ๋ฏ์ด๋ณด์.
- Git์ ๊ฐ์ฒด ์ดํด์ ์ด์ ์ ๋๊ณ ์ถ๋ค๋ฉด ์ด ๋ถ๋ถ์ ๊ฑด๋๋ฐ์ด๋ ๋ฌด๋ฐฉํ๋ค.
๐ผ ํ์ผ
๐ต config ํ์ผ
$ cat config
# ์ถ๋ ฅ
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
- Git Repository์ ๊ธฐ๋ณธ ๋์์ ์ ์ดํ๋ ์ค์ ํ์ผ์ด๋ค.
- ๊ฐ๋ณ๊ฒ ๋์ด๊ฐ์.
๐ธ repositoryformatversion
- Repository์ ํฌ๋งท ๋ฒ์ ์ ๋ปํ๋ฉฐ, ์ด๊ธฐ ํฌ๋งท์ 0์ด๋ค.
- Git์ ์ํด ์๋์ผ๋ก ๊ด๋ฆฌ๋๋ค.
๐ธ filemode
- true์ผ ์ git์ด ํ์ผ์ chmod ์คํ ๊ถํ ๋ณ๊ฒฝ์ ์ถ์ ํ๋ค.
- false์ผ ๊ฒฝ์ฐ ๊ถํ์ ๋ฌด์ํ๊ณ ๋ด์ฉ ๋ณ๊ฒฝ๋ง ์ถ์ ํ๋ค.
๐ธ bare
- bare repository์ธ์ง์ ์ฌ๋ถ๋ฅผ ๋ํ๋ธ๋ค.
- true์ผ ๊ฒฝ์ฐ bare repository๋ผ๋ ๋ป์ด๋ค.
- .git ํด๋๋ง ์ ์ฅํ๋๋ฐ, ๋ง ๊ทธ๋๋ก ํ์ผ ๋ด์ฉ(Working Directory) ์์ด git์ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ง์ ์ ์ฅํ๋ค.
- ์๋ฅผ ๋ค์ด, ์ฝ๋ ํ์ผ์ด ์กด์ฌํ ๊ฒฝ์ฐ ํ์ผ ๊ผฌ์ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์๊ธฐ ๋๋ฌธ์ .git ํด๋๋ง์ ๊ด๋ฆฌํ๋ฉฐ ๋ด๋ถ ๋ณ๊ฒฝ ์ฌํญ(์ปค๋ฐ, ๋ธ๋์น ๋ฑ)๋ง ๊ธฐ๋กํ๋ ๊ฒ์ด๋ค.
- ๋ฐ๋ผ์ bare repository๋ ๋ฒ์ (commit ๊ธฐ๋ก)๋ง์ ์ ์ฅํ๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ํ์ฉํด ์ฌ๋ฌ ์ฌ๋์ด ์ ์ฅ์๋ฅผ ๊ณต์ ํ๊ณ ํ์ ํ ์ ์๋ค.
- GitHub๋ ์ด bare repository๋ฅผ ์๋ฒ์ ์ ์ฅํ๊ณ , ์ด๋ฅผ ์ฌ์ฉ์๊ฐ ์น์์์ ์ฝ๋ ํ์ผ์ฒ๋ผ ์ฝ๊ฒ ๋ณผ ์ ์๋๋ก ์๊ฐํํด์ฃผ๋ ์๋น์ค๋ค.
- GitHub ํ๋ฉด์์ ์ฐ๋ฆฌ๊ฐ ์ฝ๋ ํ์ผ์ ๋ณด๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋ ์ด์ ๋ bare repository์ ์ ์ฅ๋ Git ๊ฐ์ฒด๋ค(blob, tree ๋ฑ)์ ํ์ผ ํํ๋ก ๋ณํํด์ ๋ณด์ฌ์ฃผ๊ธฐ ๋๋ฌธ์ด๋ค.
- .git ํด๋๋ง ์ ์ฅํ๋๋ฐ, ๋ง ๊ทธ๋๋ก ํ์ผ ๋ด์ฉ(Working Directory) ์์ด git์ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ง์ ์ ์ฅํ๋ค.
- false์ผ ๊ฒฝ์ฐ working directory๊ฐ ์กด์ฌํ๋, ์ฐ๋ฆฌ๊ฐ ์๋ ์ผ๋ฐ ๊น ์ ์ฅ์์ด๋ค.
๐ธ logallrefupdates
- ๋ธ๋์น๊ฐ ์ ๋ฐ์ดํธ๋ ๋๋ง๋ค ๋ก๊ทธ๋ฅผ ๋จ๊ธธ์ง ์ฌ๋ถ์ด๋ค.
- true์ผ ๊ฒฝ์ฐ ๋ธ๋์น๊ฐ ์ฎ๊ฒจ๊ฐ ๋๋ง๋ค .git/logs/ ๋ฐ์ ๊ธฐ๋ก์ด ์์ธ๋ค.
๐ธ ignorecase
- ํ์ผ ์ด๋ฆ ๋์๋ฌธ์ ๊ตฌ๋ถ ์ฌ๋ถ์ด๋ค.
๐ธ precomposeunicode
- ์ ๋์ฝ๋ ์ ๊ทํ ๊ด๋ จ ์ค์ ์ฌ๋ถ์ด๋ค.
- MacOS์์๋ ํ์ผ ์ด๋ฆ์ ์ ๋์ฝ๋๋ฅผ ์ ์ฅํ ๋ ์กฐํฉํ(normalization)์ผ๋ก ์ ์ฅํ๋ ๊ฒฝ์ฐ๊ฐ ์๋ค.
- true์ผ ๊ฒฝ์ฐ ์ด๋ฅผ ๊ฐ์ํด์ ์ด๋ฆ์ ๋ง์ถฐ์ ์ ์ฅํ๊ณ ๋น๊ตํ๋ค.
๐ต description ํ์ผ
$ cat description
# ์ถ๋ ฅ
Unnamed repository; edit this file 'description' to name the repository.
- ๋ฆฌํฌ์งํฐ๋ฆฌ์ ๋ํ ๊ฐ๋จํ ์ค๋ช ์ ์ ๊ณตํ๋ค.
๐ต HEAD ํ์ผ
$ cat HEAD
# ์ถ๋ ฅ
ref: refs/heads/main
- Git์์ ํ์ฌ ์ฒดํฌ์์ํ ๋ธ๋์น์ ํด๋ ๊ฒฝ๋ก๋ฅผ ๋ด๊ณ ์๋ค.
๐ผ ๋๋ ํฐ๋ฆฌ
๐ข hooks/
/hooks$ ll
# ์ถ๋ ฅ
total 120
-rwxr-xr-x 1 root staff 478 4 26 02:07 applypatch-msg.sample
-rwxr-xr-x 1 root staff 896 4 26 02:07 commit-msg.sample
-rwxr-xr-x 1 root staff 4726 4 26 02:07 fsmonitor-watchman.sample
-rwxr-xr-x 1 root staff 189 4 26 02:07 post-update.sample
-rwxr-xr-x 1 root staff 424 4 26 02:07 pre-applypatch.sample
-rwxr-xr-x 1 root staff 1643 4 26 02:07 pre-commit.sample
-rwxr-xr-x 1 root staff 416 4 26 02:07 pre-merge-commit.sample
-rwxr-xr-x 1 root staff 1374 4 26 02:07 pre-push.sample
-rwxr-xr-x 1 root staff 4898 4 26 02:07 pre-rebase.sample
-rwxr-xr-x 1 root staff 544 4 26 02:07 pre-receive.sample
-rwxr-xr-x 1 root staff 1492 4 26 02:07 prepare-commit-msg.sample
-rwxr-xr-x 1 root staff 2783 4 26 02:07 push-to-checkout.sample
-rwxr-xr-x 1 root staff 3650 4 26 02:07 update.sample
- git์ ์ด๋ฒคํธ ์๋ํ ํด๋์ด๋ค.
- ์๋ฅผ ๋ค์ด commit์ด๋ push๋ฅผ ํ ๋ ์๋์ผ๋ก ์คํ๋๋ ์คํฌ๋ฆฝํธ๊ฐ ํฌํจ๋์ด ์๋ค.
๐ข info/
/info$ ll
# ์ถ๋ ฅ
total 8
-rw-r--r-- 1 root staff 240 4 26 02:07 exclude
- ์ถ๊ฐ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ํด๋์ด๋ค.
- ์ผ๋ฐ์ ์ธ ์ค์ ์ธ์ exclude(ํน์ ํ์ผ๋ง ๋ฌด์ํ๋ ์ค์ ) ํ์ผ ๋ฑ์ด ๋ค์ด๊ฐ ์๋ค.
๐ข object/
/objects$ ll
# ์ถ๋ ฅ
total 0
drwxr-xr-x 2 root staff 64 4 26 02:07 info
drwxr-xr-x 2 root staff 64 4 26 02:07 pack
/objects/info$ls -al
# ์ถ๋ ฅ
total 0
drwxr-xr-x 2 root staff 64 4 26 02:07 .
drwxr-xr-x 4 root staff 128 4 26 02:07 ..
/objects/pack$ls -al
# ์ถ๋ ฅ
total 0
drwxr-xr-x 2 root staff 64 4 26 02:07 .
drwxr-xr-x 4 root staff 128 4 26 02:07 ..
- git์ ํต์ฌ ํด๋์ด๋ค.
- ์ฌ์ฉ์๊ฐ ๋ง๋ ์ปค๋ฐ, ํ์ผ, ํด๋ ๋ฑ ์ง์ง ๋ฐ์ดํฐ๊ฐ ๋ชจ๋ ์ฌ๊ธฐ์ ์ ์ฅ๋๋ค.
- ์์ถ๋ ํํ๋ก ์ ์ฅ๋๊ธฐ ๋๋ฌธ์ ํน์ ๋ช ๋ น์ด๋ ์ธ๋ถ parser๋ฅผ ์ฌ์ฉํ์ฌ ํด๋ ํ ์ ์๋ค.
๐ข refs/
/refs$ ll
# ์ถ๋ ฅ
total 0
drwxr-xr-x 2 root staff 64 4 26 02:07 heads
drwxr-xr-x 2 root staff 64 4 26 02:07 tags
/refs/heads$ ls -al
# ์ถ๋ ฅ
total 0
drwxr-xr-x 2 root staff 64 4 26 02:07 .
drwxr-xr-x 4 root staff 128 4 26 02:07 ..
- ๋ธ๋์น๋ ํ๊ทธ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ค.
- git init์ผ๋ก ์ด๋ ํ ์ปค๋ฐ์์
๋ ์์ ๋์๋ heads, tags ํด๋๊ฐ ๋น์ด์๋ค.
- ๋์ค์ commit์ ํ๊ฒ ๋๋ฉด heads์ ๋ธ๋์น ๋ช ์ ํ์ผ ์์ฑ๋๋ค.
- ํน์ ๋ธ๋์น๋ฅผ ์์ฑํ๋ฉด ํด๋น ๋ธ๋์น ๋ช ์ ํ์ผ์ด ์ถ๊ฐ๋๋ค.
- ์ด ํ์ผ์ ํด๋น ๋ธ๋์น๊ฐ ๊ฐ๋ฆฌํค๋ ์ปค๋ฐ์ SHA-1 ํด์๊ฐ ์ ์ฅ๋๋ค.
๐จ๐ป๐ฌ ๋ณธ๊ฒฉ์ ์ธ ์ค์ต ์์
๐๐ป git add
๐ธ git ํด๋ ๋ด ์๋ก์ด ํ์ผ ์์ฑ
# git init์ ํ ์ต์ด ํด๋ ๋ด๋ถ์์ fitst.text ํ์ผ์ i am iron man. ์
๋ ฅ ํ ์ ์ฅ
$ echo "i am iron man." > first.text
$ ll
# ์ถ๋ ฅ
total 8
-rw-r--r-- 1 root staff 15 4 28 01:39 first.text
- ์ฐ์ ์๋ก์ด ํ์ผ์ ์์ฑํ๋ค.
- ์ต์ด ์์ฑํ๊ฒ ๋๋ฉด Git์ ์ํด ์ถ์ ๋์ง ์๊ณ ์๋ untracked ํ์ผ์ด ์ถ๊ฐ๋๋ค.
๐ธ git add - ์คํ ์ด์ง ์์ญ์ ์๋ก์ด ํ์ผ ์ถ๊ฐํ๊ธฐ
# git add ํ๊ธฐ ์
$ git status # ์ํ ํ์ธ ๋ช
๋ น์ด
# ์ถ๋ ฅ
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
first.text
nothing added to commit but untracked files present (use "git add" to track)
# git add ํ ํ
$ git add first.text
$ git status
# ์ถ๋ ฅ
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: first.text
- git add ๋ช ๋ น์ด๋ฅผ ํ๊ธฐ ์ ๊ณผ ํ git status๋ฅผ ํ์ธํด ๋ณด๋ฉด Git์ด first.text ํ์ผ์ ์ถ์ ํ๊ณ ์์ง ์๋ค๊ฐ, ์ถ์ ํ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
- ์ด๋ git add๋ก ์ธํด first.text ํ์ผ์ด ์คํ
์ด์ง ์์ญ(Index)์ผ๋ก ๋ค์ด๊ฐ์์ ์๋ฏธํ๋ค.
- ์์ง ์ปค๋ฐํ์ง ์์์ง๋ง, ์ปค๋ฐํ ์ค๋น๋ฅผ ๋๋๋ค๊ณ ๋ณผ ์ ์๋ค.
๐ธ Git ๋ด๋ถ์์๋?
# ์คํ
์ด์ง ์์ญ ์ ๋ณด ํ์ธ ๋ช
๋ น์ด
$ git ls-files --stage
# ์ถ๋ ฅ
100644 8e21e230620d2380b2fee92cf506ea4e4dc3363a 0 first.text
# objects ํด๋ ๋ด blob ๊ฐ์ฒด ์์ฑ ํ์ธํด๋ณด๊ธฐ
/.git/objects$ ll
# ์ถ๋ ฅ
total 0
drwxr-xr-x 3 root staff 96 4 28 01:43 8e
drwxr-xr-x 2 root staff 64 4 26 02:07 info
drwxr-xr-x 2 root staff 64 4 26 02:07 pack
/.git/object$ cd 8e
/.git/objects/8e$ ll
# ์ถ๋ ฅ
total 8
-r--r--r-- 1 root staff 31 4 28 01:43 21e230620d2380b2fee92cf506ea4e4dc3363a
# blob ๊ฐ์ฒด ๋ด์ฉ ํ์ธ ํด๋ณด๊ธฐ
$ git cat-file -p 8e21e230620d2380b2fee92cf506ea4e4dc3363a
# ์ถ๋ ฅ
i am iron man.
- git add ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด first.text ํ์ผ์ ๋ด์ฉ์ ์ฝ๊ณ SHA-1 ํด์๋ฅผ ์์ฑ(๋ค๋ฅธ ๊ฐ์ฒด๋ ๋ง์ฐฌ๊ฐ์ง)ํ๋ค.
- ์ด ๋ด์ฉ์ blob ๊ฐ์ฒด๋ก ๋ง๋ค์ด .git/object ํด๋ ์์ ์ ์ฅํ๋๋ฐ ํด์๊ฐ์ ์ ๋ ๊ธ์๋ฅผ ํด๋๋ช
์ผ๋ก ํ๊ณ ๋๋จธ์ง ๊ธ์๋ฅผ ๋ด๋ถ ํ์ผ๋ช
์ผ๋ก ํ๋ค.
- ์์์ ํ์ธํ ์ ์๋ฏ์ด ๋ง๋ค์ด์ง blob ๊ฐ์ฒด๋ ํ์ผ์ ๋ด์ฉ์ ์ ์ฅํ๊ณ ์๋ค.
๐ธ .git/index
/.git$ ll
# ์ถ๋ ฅ
total 40
-rw-r--r-- 1 root staff 137 4 26 02:07 config
-rw-r--r-- 1 root staff 73 4 26 02:07 description
-rw-r--r-- 1 root staff 21 4 26 02:07 HEAD
drwxr-xr-x 15 root staff 480 4 26 02:07 hooks
-rw-r--r-- 1 root staff 145 4 28 02:10 index # ์๋ก ์์ฑ
drwxr-xr-x 3 root staff 96 4 26 02:07 info
drwxr-xr-x 4 root staff 128 4 28 02:10 logs
drwxr-xr-x 7 root staff 224 4 28 02:10 objects
drwxr-xr-x 4 root staff 128 4 26 02:07 refs
# cat ๋ช
๋ น์ด๋ก ๋ด๋ถ ๋ด์ฉ ํ์ธํ๊ธฐ(์คํจ)
/.git$ cat index
# ์ถ๋ ฅ
#????,??NM?6:?'za?
first.textTREE1 0
#??t"/?R?? ?nSz?q?H?9x???฿ฃ8???@??%
# ๋ณ๋์ ๋ช
๋ น์ด๋ก ๋ด๋ถ ๋ด์ฉ ํ์ธํ๊ธฐ(์ฑ๊ณต)
/.git$ git ls-files --stage
# ์ถ๋ ฅ
100644 8e21e230620d2380b2fee92cf506ea4e4dc3363a 0 first.text
- .git/index๊ฐ ์๋ก ์์ฑ๋์๋ค. ์ด๋ Git์ ์คํ
์ด์ง ์์ญ์ ๊ตฌํํ๋ ๋ฐ์ด๋๋ฆฌ ํ์ผ์ด๋ค.
- ์ด ํ์ผ์๋ git add๋ฅผ ํตํด ์ถ๊ฐ๋ ํ์ผ๋ค์ blob ํด์์ ๋ฉํ ์ ๋ณด๊ฐ ์ ์ฅ๋๋ค.
- .git/index๋ ๋ฐ์ด๋๋ฆฌ ํฌ๋งท์ด๋ฏ๋ก cat ๊ฐ์ ๋ช ๋ น์ด๋ก ๋ณด๋ฉด ๊นจ์ง๋ค.
- git ls-files --stage์ ๊ฐ์ ๋ณ๋์ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ฉด ๊ฐ ํ์ผ์ blob ํด์์ ์คํ ์ด์ง ์ ๋ณด๋ฅผ ํ์ธํ ์ ์๋ค.
๐๐ป git commit
$ git commit -m "first commit"
# ์ถ๋ ฅ
[main (root-commit) b19a9f1] first commit
1 file changed, 1 insertion(+)
create mode 100644 first.text
- ์ฒซ ๋ฒ์งธ commit์ด ์คํ๋จ์ผ๋ก์จ Git์ first.text๋ผ๋ ํ์ผ์ ๊ด๋ฆฌํ๋ฉฐ, ์ฒซ๋ฒ์งธ ๋ฒ์ ์ ๊ธฐ์ตํ๊ณ ์๊ฒ ๋์๋ค.
๐ธ Git ๋ด๋ถ์์๋?
/.git$ cd objects
/.git/objects$ll
# ์ถ๋ ฅ
total 0
drwxr-xr-x 3 root staff 96 4 28 02:10 82 # ์๋ก ์์ฑ
drwxr-xr-x 3 root staff 96 4 28 01:43 8e
drwxr-xr-x 3 root staff 96 4 28 02:10 b1 # ์๋ก ์์ฑ
drwxr-xr-x 2 root staff 64 4 26 02:07 info
drwxr-xr-x 2 root staff 64 4 26 02:07 pack
# ํ์ฌ HEAD๊ฐ ๋ฐ๋ผ๋ณด๋ ์ปค๋ฐ ํด์ ์กฐํ
/.git$ git rev-parse HEAD
# ์ถ๋ ฅ
b19a9f14568ce6ed7b22f02f2cecdd6aeff6929e
- .git/objects/์ tree, commit ๊ฐ์ฒด๊ฐ ์ถ๊ฐ๋จ์ ํ์ธํ ์ ์๋ค.
- ์ฐธ๊ณ ๋ก, ํ์ฌ HEAD์ ์ปค๋ฐ ํด์๋ฅผ ํ์ธํ๋ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ฉด commit ๊ฐ์ฒด์ ํด์๊ฐ์ด ๋์จ๋ค.
๐ธ refs/heads
/.git/$ cd refs
/.git/refs$ cd heads
/.git/refs/heads$ ll
# ์ถ๋ ฅ
total 8
-rw-r--r-- 1 root staff 41 4 28 02:10 main
# main ์ถ๋ ฅ
/.git/refs/heads$ cat main
b19a9f14568ce6ed7b22f02f2cecdd6aeff6929e
- ๋ํ, .git/refs/heads/main์ ์ด ์ปค๋ฐ ๊ฐ์ฒด์ ํด์๊ฐ์ด ๊ธฐ๋ก๋๋ค.
๐ธ commit ๊ฐ์ฒด๋ก tree, blob ํด์๊ฐ ์ฐพ์๋ณด๊ธฐ
# ๊ฐ์ฒด ํ์
ํ์ธ
/.git$ git cat-file -t b19a9f14568ce6ed7b22f02f2cecdd6aeff6929e
# ์ถ๋ ฅ
commit
# ๊ฐ์ฒด ์ ๋ณด ํ์ธ
/.git$ git cat-file -p b19a9f14568ce6ed7b22f02f2cecdd6aeff6929e
# ์ถ๋ ฅ
tree 82a374221b7e2f8252a0f020c56e53167aab71b0
author root <111210881+xxxxxx@users.noreply.github.com> 1745773845 +0900
committer root <111210881+xxxxxx@users.noreply.github.com> 1745773845 +0900
# ๊ฐ์ฒด ์ ๋ณด ํ์ธ
/.git$ git cat-file -p 82a374221b7e2f8252a0f020c56e53167aab71b0
# ์ถ๋ ฅ
100644 blob 8e21e230620d2380b2fee92cf506ea4e4dc3363a first.text
- git cat-file -t์ ๊ฒฝ์ฐ ๊ฐ์ฒด์ ํ์ ์ ์ถ๋ ฅํ๋ค.
- git cat-file -p์ ๊ฒฝ์ฐ ๊ฐ์ฒด์ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ค.
- ์ด๋ฅผ ์ด์ฉํ์ฌ commit๊ฐ์ฒด๋ฅผ ๊ฐ์ง๊ณ tree์ blob ๊ฐ์ฒด๊น์ง ํด์๋ฅผ ์ฐพ์ ์ ์๋ค.
๐ซฅ ์ค๊ฐ ์ ๋ฆฌ
- Git์ add์ commit ๊ณผ์ ์ ํตํด ๋ด๋ถ์ ์ผ๋ก blob, tree, commit ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ , ์ด๋ฅผ ํตํด ํ์ผ๊ณผ ๋๋ ํฐ๋ฆฌ์ ๋ณ๊ฒฝ ๋ด์ญ์ ์ถ์ ํ๊ณ ๊ด๋ฆฌํ๋ค๋ ๊ฒ์ ํ์ธํ ์ ์์๋ค.
โ๐ป 2 ๋จ๊ณ: ๋ธ๋์น๋ฅผ ๋๋๊ณ merge ํด๋ณด๊ธฐ
- ์ด์ ๋ธ๋์น๋ฅผ ๋๋๊ณ merge ํ๋ ๊ณผ์ ์ ๊ฐ๋ณ๊ฒ ์์๋ณด์. Git ๋ด๋ถ์ ์ธ ๊ฐ์ฒด์ ๋ณํ๋ ์์ ์ถฉ๋ถํ ์ค๋ช ํ์ผ๋ฏ๋ก ์๋น ๋ถ๋ถ ์๋ตํ๋ค.
๐๐ป git checkout -b feature/test1
# feature/test1 ๋ธ๋์น๋ก ๋ณ๊ฒฝ
$ git checkout -b feature/test1
# ์ถ๋ ฅ
Switched to a new branch 'feature/test1'
# HEAD์ ๋ธ๋์น ์กฐํํ์ฌ ๋ธ๋์น ๋ณ๊ฒฝ ํ์ธ
/.git $cat HEAD
ref: refs/heads/feature/test1
# ์ค์ ํด๋ ๊ฒฝ๋ก ๋ค์ด๊ฐ์ ์๋ก ์์ฑ๋จ์ ํ์ธํด๋ณด๊ธฐ
/.git$ cd refs/heads
/.git/refs/heads$ ll
# ์ถ๋ ฅ
total 8
drwxr-xr-x 3 root staff 96 4 29 02:32 feature # ์๋ก ์์ฑ
-rw-r--r-- 1 root staff 41 4 28 02:10 main
/feature$ ll
# ์ถ๋ ฅ
total 8
-rw-r--r-- 1 wonyong staff 41 4 29 02:32 test1
- ์๋ก์ด ๋ธ๋์น๋ฅผ ๋ง๋ค๊ณ HEAD ๋ธ๋์น๋ฅผ ์กฐํํ๋ฉด ๋ณ๊ฒฝ๋ ๋ธ๋์น์์ ํ์ธํ ์ ์๋ค.
- ๋ํ, ํด๋น ๊ฒฝ๋ก๋ก ๋ค์ด๊ฐ ๋ณด๋ฉด feature/test1์ด๋ผ๋ ์๋ก์ด ๋ธ๋์น ํด๋ ๋ฐ ํ์ผ์ด ์์ฑ๋์ด ์์์ ์ ์ ์๋ค.
๐ธ ํ์ผ ๋ณ๊ฒฝํด ๋ณด๊ธฐ
# ํ์ผ ๋ณ๊ฒฝ ์
/git-internal-test$ git status
# ์ถ๋ ฅ
On branch feature/test1
nothing to commit, working tree clean
# ํ์ผ ๋ณ๊ฒฝ
/git-internal-test$ echo "i am not iron man." > first.text # ">"๋ ํ์ผ ๋ฎ์ด์ฐ๊ธฐ์
/git-internal-test$ git status
# ์ถ๋ ฅ
On branch feature/test1
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: first.text
no changes added to commit (use "git add" and/or "git commit -a")
- ์์ ์ค๋ช ์ ์ด์ด feature/test1์์ ์งํ ์ค์ด๋ค.
- ํ์ผ์ด ๋ณ๊ฒฝ์ฌํญ์ด ์๋ unmodified์๋ค๊ฐ, ํ์ผ์ ์์ ํ์ฌ modified๋ก ๋ณ๊ฒฝ๋์๋ค.
๐ธ blob ๊ฐ์ฒด ์ถ๊ฐ ํ์ธํ๊ธฐ
/git-internal-test$ git add first.text
/git-internal-test$ cd .git/objects
/.git/objects$ ll
# ์ถ๋ ฅ
total 0
drwxr-xr-x 3 root staff 96 4 28 02:10 82
drwxr-xr-x 3 root staff 96 4 28 01:43 8e # ์ฒซ๋ฒ์งธ blob ๊ฐ์ฒด
drwxr-xr-x 3 root staff 96 4 29 02:47 9f # ์๋ก ์ถ๊ฐ๋ blob ๊ฐ์ฒด
drwxr-xr-x 3 root staff 96 4 28 02:10 b1
drwxr-xr-x 2 root staff 64 4 26 02:07 info
drwxr-xr-x 2 root staff 64 4 26 02:07 pack
# ์คํ
์ด์ง ์์ญ ์ ๋ณด ํ์ธํ๊ธฐ
$ git ls-files --stage
# ์ถ๋ ฅ(first.text์ ํด๋นํ๋ blob ๊ฐ์ฒด์ ํด์๊ฐ์ด ๋ณ๊ฒฝ๋จ)
100644 9fe8f948e6de78c9f7627aba2632e6b0c80c6fb7 0 first.text
- ์์ ์ค๋ช ์ ์ด์ด feature/test1์์ ์งํ ์ค์ด๋ค.
- git add ๋ช ๋ น์ด๋ก first.text์ ๋ณ๊ฒฝ ์ฌํญ์ ์คํ ์ด์ง ์์ญ์ผ๋ก ์ฌ๋ ธ๋ค.
- ๋ณ๊ฒฝ๋ ์๋ก์ด blob ๊ฐ์ฒด๊ฐ ์์ฑ๋์์์ ํ์ธํ ์ ์๋ค.
- ๋ํ ์คํ ์ด์ง ์์ญ ์ ๋ณด๋ฅผ ์ถ๋ ฅํด ๋ณด๋ฉด ์๋ก ์ถ๊ฐ๋ blob ๊ฐ์ฒด๋ก ํด์๊ฐ์ด ๋ณ๊ฒฝ๋์์์ ํ์ธํ ์ ์๋ค.
๐๐ป git commit
# ๋๋ฒ์งธ ์ปค๋ฐํ๊ธฐ
$ git commit -m "second commit"
# ์ถ๋ ฅ
[feature/test1 8ed69f8] second commit
1 file changed, 1 insertion(+), 1 deletion(-)
# ์ปค๋ฐ ์ ๋ณด ํ์ธํ๊ธฐ
$ git rev-parse HEAD
8ed69f812495b68a4bafb47074f8efa7e9a0e845
# object์ ๋๋ฒ์งธ ์ปค๋ฐ์ ์ํด ์ถ๊ฐ๋ tree, commit ๊ฐ์ฒด ํ์ธํด๋ณด๊ธฐ
/.git$ cd objects
/.git/objects$ ll
# ์ถ๋ ฅ
total 0
drwxr-xr-x 3 root staff 96 4 29 02:50 76 # ๋๋ฒ์งธ tree ๊ฐ์ฒด
drwxr-xr-x 3 root staff 96 4 28 02:10 82 # ์ฒซ๋ฒ์งธ tree ๊ฐ์ฒด
drwxr-xr-x 4 root staff 128 4 29 02:50 8e # ๋๋ฒ์งธ commit ๊ฐ์ฒด, ์ฒซ๋ฒ์งธ blob ๊ฐ์ฒด(๋ ๊ฐ์ฒด์ ํด์๊ฐ ์ฒซ ๋์๋ฆฌ๊ฐ ๊ฐ์์ ๊ฐ์ ํด๋์ ๋ค์ด๊ฐ)
drwxr-xr-x 3 root staff 96 4 29 02:47 9f # ๋๋ฒ์งธ blob ๊ฐ์ฒด
drwxr-xr-x 3 root staff 96 4 28 02:10 b1 # ์ฒซ๋ฒ์งธ commit ๊ฐ์ฒด
drwxr-xr-x 2 root staff 64 4 26 02:07 info
drwxr-xr-x 2 root staff 64 4 26 02:07 pack
# commit ๊ฐ์ฒด ์ ๋ณด ์ถ๋ ฅ
$ git cat-file -p 8ed69f812495b68a4bafb47074f8efa7e9a0e845
tree 766ad35e3fee28e3b41e90d64ee650546fa88383
parent b19a9f14568ce6ed7b22f02f2cecdd6aeff6929e # ๋ถ๋ชจ tree ๊ฐ์ฒด ์ถ๊ฐ
author root <111210881+xxxxxx@users.noreply.github.com> 1745862647 +0900
committer root <111210881+xxxxxx@users.noreply.github.com> 1745862647 +0900
second commit
# ๊น ์ปค๋ฐ ๊ทธ๋ํ ์ถ๋ ฅ
$ git log --oneline --graph --all
* 8ed69f8 (HEAD -> feature/test1) second commit
* b19a9f1 (main) first commit
- ์์ ์ค๋ช ์ ์ด์ด feature/test1์์ ์งํ ์ค์ด๋ค.
- commit์ ์๋ฃํ๋ฉด ์๋ก์ด tree ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ค.
- commit์ ์๋ฃํ๋ฉด commit ๊ฐ์ฒด๊ฐ ์๋ก ๋ง๋ค์ด์ง๋ค.
- ๋ํ, ๋ ๋ฒ์งธ commit ๊ฐ์ฒด ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ฉด ๋ถ๋ชจ tree ๊ฐ์ฒด๊ฐ ๋ฌด์์ธ์ง ์ถ๊ฐ๋ก ํ์๋๋ค.
- ์ปค๋ฐ ์ด๋ ฅ์ ๊ทธ๋ํ ํ์์ผ๋ก ์ถ๋ ฅํ๋ฉด feature/test1 ๋ธ๋์น์์ second commit ๊ธฐ๋ก์ด ์ถ๊ฐ๋์์์ ํ์ธํ ์ ์๋ค.
๐ธ main ๋ธ๋์น๋ก ๋์์ค๊ธฐ
$ git checkout main
# ์ถ๋ ฅ
Switched to branch 'main'
# main ๋ธ๋์น๋ก ๋์์ ์คํ
์ด์ง ์์ญ ์ ๋ณด ์ถ๋ ฅํ๊ธฐ
$ git ls-files --stage
100644 8e21e230620d2380b2fee92cf506ea4e4dc3363a 0 first.text
# main ๋ธ๋์น๋ก ๋์์ HEAD์ ์ปค๋ฐ ๊ฐ์ฒด ํด์๊ฐ ์ถ๋ ฅํ๊ธฐ
$ git rev-parse HEAD
# ์ถ๋ ฅ
b19a9f14568ce6ed7b22f02f2cecdd6aeff6929e
- main ๋ธ๋์น๋ก ๋์์ค๋ฉด ๊ธฐ์กด์ ์๋ ๊ทธ๋๋ก ์ฒซ ๋ฒ์งธ ์คํ
์ด์ง ์์ญ์ blob ๊ฐ์ฒด์, ์ฒซ๋ฒ์งธ commit ๊ฐ์ฒด ํด์๊ฐ์ด ์ถ๋ ฅ๋จ์ ํ์ธํ ์ ์๋ค.
- main ๋ธ๋์น๋ก ๋์์ค๋ฉด HEAD๊ฐ ๋ค์ main ๋ธ๋์น์ ๋ง์ง๋ง ์ปค๋ฐ์ ๊ฐ๋ฆฌํค๊ณ , .git/index๋ ํด๋น ์ปค๋ฐ์ ๋ง๊ฒ ๋ณต์๋๊ธฐ ๋๋ฌธ์ด๋ค.
- ๋ฐ๋ผ์ ์ด์ ์ main ๋ธ๋์น์์ ์คํ ์ด์ง ๋ ์ํ์ commit ๋ด์ฉ์ด ๊ทธ๋๋ก ์ถ๋ ฅ๋๋ ๊ฒ์ด๋ค.
- ๋ธ๋์น๋ง๋ค HEAD ํฌ์ธํฐ๊ฐ ๊ฐ๋ฆฌํค๊ณ ์๋ commit ๊ฐ์ฒด๊ฐ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ์์ ๊ฐ์ด ๋ธ๋์น ๋ณ ์์ ์ด ๊ฐ๋ฅํ ๊ฒ์ด๋ค.
๐๐ป git merge
- ์ฐ์ main ๋ธ๋์น์ feature/test1์ merge ํด๋ณด์.
# main ๋ธ๋์น์์ first.txt ์ถ๋ ฅ
$ cat first.text
# ์ถ๋ ฅ
i am iron man. # ๋งจ ์ฒ์ main ๋ธ๋์น์ ๋ด์ฉ
# main ๋ธ๋์น์์ ๊น ์ปค๋ฐ ๊ทธ๋ํ ์ถ๋ ฅ
$ git log --oneline --graph --all
# ์ถ๋ ฅ
* 8ed69f8 (feature/test1) second commit
* b19a9f1 (HEAD -> main) first commit # HEAD๊ฐ main์ผ๋ก ๋์ด
# main ๋ธ๋์น์์ ์๋ก์ด ํ์ผ ์ถ๊ฐ
$ echo "i am thanos." >> second.txt
# git add & git commit
$ git add second.txt
$ git commit -m "second commit in main"
# ์ถ๋ ฅ
[main 0a4bb61] second commit in main
1 file changed, 1 insertion(+)
create mode 100644 second.txt
# main ๋ธ๋์น์์ ๊น ์ปค๋ฐ ๊ทธ๋ํ ๋ค์ ์ถ๋ ฅ
# A : ํ์ฌ main ๋ธ๋์น(first commit ๋๋น ๋ณ๊ฒฝ์ฌํญ : second.txt "i am thanos.")
# B : feature/test1 ๋ธ๋์น(first commit ๋๋น ๋ณ๊ฒฝ์ฌํญ : first.text "i am not iron man.")
$ git log --oneline --graph --all
* 0a4bb61 (HEAD -> main) second commit in main # A
| * 8ed69f8 (feature/test1) second commit # B
|/
* b19a9f1 first commit
# feature/test1 ๋ธ๋์น์ merge ํด๋ณด๊ธฐ
$ git merge feature/test1
# ์ถ๋ ฅ
Merge made by the 'ort' strategy.
first.text | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
# first.txt ๋ณ๊ฒฝ์ฌํญ ํ์ธ
$ cat first.text
# ์ถ๋ ฅ
i am not iron man.
# merge ํ main ๋ธ๋์น์์ ๊น ์ปค๋ฐ ๊ทธ๋ํ ์ถ๋ ฅํ๊ธฐ
$ git log --oneline --graph --all
# ์ถ๋ ฅ
# merge(first.text "i am not iron man., second.txt "i am thanos.")
* 283c20c (HEAD -> main) Merge branch 'feature/test1'
|\
| * 8ed69f8 (feature/test1) second commit
* | 0a4bb61 second commit in main
|/
* b19a9f1 first commit
# merge commit ๊ฐ์ฒด ์ ๋ณด ์กฐํํ๊ธฐ
/.git/objects/28$ git cat-file -p 283c20c2160c49dcade03214b6755cea8c370833
# ์ถ๋ ฅ(ํ์ฌ ๋ธ๋์น์ ๋ณํฉ ๋์ ๋ธ๋์น์ ์ปค๋ฐ ํด์๊ฐ parent commit ํด์๋ก ๋ ๊ฐ ๋์จ๋ค.)
tree 39b858e782d8e744d823614963c8b20b685730f2
parent 0a4bb610d806d091823ffed17f3add24bd859e3f
parent 8ed69f812495b68a4bafb47074f8efa7e9a0e845
author root <111210881+xxxxxx@users.noreply.github.com> 1745866013 +0900
committer root <111210881+xxxxxx@users.noreply.github.com> 1745866013 +0900
- merge์ ์ฑ๊ณตํ๋ฉด feature/test1 ๋ธ๋์น์ ๋ณ๊ฒฝ ๋ด์ฉ์ด main ๋ธ๋์น์ ๋ฐ์๋๊ณ , ๋ ๋ธ๋์น์ ๊ธฐ๋ก์ ์ฐ๊ฒฐํ๋ ์๋ก์ด merge commit์ด ์์ฑ๋๋ค.
- ์์ ์์๋ฅผ ๋ณด๋ฉด main ๋ธ๋์น์ second.txt ํ์ผ("i am thanos.")์ feature/test1 ๋ธ๋์น์ first.text ํ์ผ("i am not iron man.")์ด ๋ชจ๋ ๋ฐ์๋ ์๋ก์ด merge commit์ด ์์ฑ๋๋ ๊ฒ์ด๋ค.
- ํด๋น merge commit ๊ฐ์ฒด๋ parent๊ฐ ๋ ๊ฐ(ํ์ฌ ๋ธ๋์น, ๋ณํฉ ๋์ ๋ธ๋์น์ commit ๊ฐ์ฒด)์ด๋ค.
- ์ด ๊ณผ์ ์์ ๋ณํฉ๋ ํ์ผ ๊ตฌ์กฐ๋ฅผ ๋ํ๋ด๋ tree ๊ฐ์ฒด๊ฐ ์๋ก ๋ง๋ค์ด์ง๋ฉฐ, ํ์ผ ๋ด์ฉ์ด ์ถ๊ฐ๋ก ๋ณ๊ฒฝ๋ ๊ฒฝ์ฐ์๋ blob ๊ฐ์ฒด๋ ํจ๊ป ์์ฑ๋๋ค.
๐ธ ๊ณ ์๋ก ์ถฉ๋ ๋ด๋ณด๊ธฐ
# main ๋ธ๋์น์์ feature/test2 ๋ธ๋์น ์์ฑ
/git-internal-test$ git checkout -b feature/test2
# ์ถ๋ ฅ
Switched to a new branch 'feature/test2'
# second.txt์ ๋ฌธ์ฅ ์ถ๊ฐ
$ echo "i am thor" >> second.txt
# feature/test2์ second.txt ์ถ๋ ฅํด๋ณด๊ธฐ
$ cat second.txt
# ์ถ๋ ฅ
i am thanos.
i am thor
# main ๋ธ๋์น๋ก ๋์์ค๊ธฐ
$ git switch main
# ์ถ๋ ฅ
Switched to branch 'main'
# second.txt์ ๋ค๋ฅธ ๋ฌธ์ฅ ์ถ๊ฐ
$ echo "i am captain america" >> second.txt
# main์ second.txt ์ถ๋ ฅํด๋ณด๊ธฐ
$ cat second.txt
# ์ถ๋ ฅ
i am thanos.
i am captain america
# ๊น ์ปค๋ฐ ๊ทธ๋ํ ์ถ๋ ฅํด๋ณด๊ธฐ
$ git log --oneline --graph --all
# ์ถ๋ ฅ
# main ๋ธ๋์น๋ "i am captain america"
# test2 ๋ธ๋์น๋ "i am thor"
* 41b266d (HEAD -> main) feature/test2 - captain america
| * 4b19a0f (feature/test2) feature/test2 - thor
|/
* 283c20c Merge branch 'feature/test1'
|\
| * 8ed69f8 (feature/test1) second commit
* | 0a4bb61 second commit in main
|/
* b19a9f1 first commit
# merge ํด๋ณด๊ธฐ
$ git merge feature/test2
# ์ถ๋ ฅ(second.txt์ ๋ด์ฉ์ด ๋ฌ๋ผ ์ถฉ๋ ๋ฐ์)
Auto-merging second.txt
CONFLICT (content): Merge conflict in second.txt
Automatic merge failed; fix conflicts and then commit the result.
# main์ second.txt ๋ค์ ์ถ๋ ฅํด๋ณด๊ธฐ
$ cat second.txt
# ์ถ๋ ฅ(Git์์ ์น์ ํ ์ถฉ๋ ์ง์ ์ ํ์ํด์ค)
i am thanos.
# <<<<<<< HEAD
i am captain america
=======
i am thor
>>>>>>> feature/test2
# ์ง์ ์์ ํ๋ , ์๋ ๋ช
๋ น์ด๋ก ์์ ํ๋ main์ ๋ณ๊ฒฝ์ฌํญ์ ๊ธฐ์ค์ผ๋ก ํ๊ธฐ
$ git checkout --ours second.txt
# main์ second.txt ๋ค์ ์ถ๋ ฅํด๋ณด๊ธฐ
$ cat second.txt
# ์ถ๋ ฅ(main์ ๋ณ๊ฒฝ ์ฌํญ์ ๊ธฐ์ค์ผ๋ก ํ์ฌ ์ถฉ๋ ํด๊ฒฐ ํจ.)
i am thanos.
i am captain america
# git add & commit ํตํด merge commit ์์ฑํ์ฌ ์ถฉ๋ ํด๊ฒฐ
$ git add second.txt
$ git commit -m "merge conflict solved"
# ์ถ๋ ฅ
[main 3e7e5ea] merge conflict solved
# ๊น ์ปค๋ฐ ๊ทธ๋ํ ๋ค์ ์ถ๋ ฅํด๋ณด๊ธฐ
# A : merge ์ถฉ๋์ ํด๊ฒฐํ ์๋ก์ด merge ์ปค๋ฐ์ด ์์ฑ ๋จ
# B : ์ถฉ๋ ์ปค๋ฐ("i am thor")
# C : ์ถฉ๋ ์ปค๋ฐ("i am captain america")
$ git log --oneline --graph --all
* 3e7e5ea (HEAD -> main) merge conflict solved # A
|\
| * 4b19a0f (feature/test2) feature/test2 - thor # B
* | 41b266d feature/test2 - captain america # C
|/
* 283c20c Merge branch 'feature/test1'
|\
| * 8ed69f8 (feature/test1) second commit
* | 0a4bb61 second commit in main
|/
* b19a9f1 first commit
- ์ถฉ๋์ด ๋ฐ์ํ ํ git checkout --ours ๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํด ํ์ฌ(main) ๋ธ๋์น์ ๋ด์ฉ์ ์ ํํ๋ค.
- Auto๋ก ์ถฉ๋์ ํด๊ฒฐํ ์ ์์ด ์๋์ผ๋ก ์ง์ ์ถฉ๋์ ํด๊ฒฐํ ๊ฒ์ด๋ค.
- ์ดํ git add๋ก ๋ณ๊ฒฝ ์ฌํญ(merge ์ถฉ๋ ํด๊ฒฐํ ๋ถ๋ถ)์ ์คํ ์ด์ง ์์ญ์ ์ฌ๋ ธ๋ค.
- ์ด ๊ณผ์ ์์ ๋ณ๊ฒฝ๋ ๋ด์ฉ์ ๋ฐ๋ผ ์๋ก์ด blob ๊ฐ์ฒด๊ฐ ์์ฑ๋ ์๋ ์๋ค.
- ์๋ฅผ ๋ค์ด, ์ง๊ธ๊ณผ ๊ฐ์ด ํ์ฌ(main) ๋ธ๋์น์ ๋ด์ฉ์ ๊ทธ๋๋ก ๋ฐ๋ฅด๋ฉด ๊ธฐ์กด blob ๊ฐ์ฒด๋ฅผ ๊ทธ๋๋ก ์ฐธ์กฐํ์ฌ ์๋ก์ด blob ๊ฐ์ฒด๊ฐ ์์ฑ๋์ง ์์ ๊ฒ์ด๋ค.
- ๋ง์ฝ, "i am antman."๊ณผ ๊ฐ์ ์ ํ ๋ค๋ฅธ ์๋ก์ด ๋ด์ฉ์ผ๋ก ์์ ํ์ฌ ์ถฉ๋์ ํด๊ฒฐํ๋ฉด ์๋ก์ด blob ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ค.
- ๋ง์ง๋ง์ผ๋ก git commit์ ์คํํ๋ฉด ๋ณ๊ฒฝ ๋ด์ฉ์ ๋ฐ์ํ tree ๊ฐ์ฒด์ ๋ ๋ถ๋ชจ๋ฅผ ๊ฐ์ง merge commit ๊ฐ์ฒด๊ฐ ์์ฑ๋๋ฉฐ, ๋ณํฉ ๊ฒฐ๊ณผ๊ฐ Git์ ์ต์ข ์ ์ผ๋ก ๊ธฐ๋ก๋๋ค.
์ฐธ๊ณ
Chat GPT
2025 ์คํ์์ค ์ปจํธ๋ฆฌ๋ทฐ์ ์์นด๋ฐ๋ฏธ Git & Redis ์์ ์๋ฃ
728x90
'[Git]' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Git Push & Clone & Pull (1) | 2023.08.10 |
---|---|
git์ ์ํ ์์ญ(add โ commit โ push) (0) | 2023.07.31 |
GitHub ์๊ฒฉ ๋ ํ์งํ ๋ฆฌ๋ฅผ ๋ง๋๋ ๋ฐฉ๋ฒ, ๋ก์ปฌ ๋ ํ์งํ ๋ฆฌ์ ์ฐ๊ฒฐํ๊ธฐ (0) | 2023.07.27 |
GitHub ์๊ฒฉ ๋ ํ์งํ ๋ฆฌ์ ์ก์ธ์คํ๋ ๋ค์ํ ์ธ์ฆ ๋ฐฉ๋ฒ (0) | 2023.07.18 |
git init์ ์ด์ฉํ์ฌ ๋ก์ปฌ ๋ ํ์งํ ๋ฆฌ ๋ง๋๋ ๋ฐฉ๋ฒ (0) | 2023.07.12 |