09. git best practice - nephilim/js-git-kata GitHub Wiki
Git Best Practice
Branch-per-Freature
- ์ฃผ์ ์์น
- feature๋ ๊ฐ๋ฅํ๋ฉด atomicํ๊ฒ(OCP๋ฅผ ์ง์ผ์), ์๊ฒ ์์ฑํ๋ค.
- feature ๋ธ๋์น๋ฅผ ISSUE-023 ํํ๋ก ์ด์ ๊ด๋ฆฌ์์ ticket๊ณผ ํํ ์ฐ๊ฒฐ์ํจ๋ค.
- dev master ๋ฑ์ ์ง์ ์ปค๋ฐํ์ง ์๋๋ค.
- git flow์์๋ ๊ฐ๋ฅํ๊ธดํ๋ค.
- integration
-
์ต๋ํ ์์ฃผ ์คํ
-
git-show-branch
-
๋ธ๋์น๊ฐ ์ด๋์ ์๋๊ฐ? ํ์ฌ ๋ธ๋์น์ ๊ธฐ์ ์ถ์ ์ ํธ๋ฆฌ
! [git] /Users/nephilim/.dotfiles/git/bin ์ ๋ฆฌ * [master] Merge branch 'shell': md2docx added ! [shell] shell: md2docx added ! [vim-plugin] vim: rnu(relative number unit) ์ ๊ฑฐ ---- - [master] Merge branch 'shell': md2docx added *+ [shell] shell: md2docx added *+ [shell^] taskit: help message typo fixed * [master^] zsh: JAVA_HOME libexec/javahome ์ ์ด์ฉํ์ฌ ๊ฒฝ๋ก ์ค์ *+ [shell~2] taskit: weekday(mon, tue, ...) based registration added *+ [shell~3] choojerk: push notification (via parse.io) added *+ [shell~4] choojerk: web crawling script for Google I/O *+ [shell~5] taskit: task list escape added *+ [shell~6] taskit: tast select & done menu added *+ [shell~7] taskit: tasklist selection&store menu *+ [shell~8] google tasks api๋ฅผ ์ด์ฉํ task adder *+ [shell~9] dev command ์์ +* [git] /Users/nephilim/.dotfiles/git/bin ์ ๋ฆฌ +*+ [shell~10] git: git-track-branch ์ถ๊ฐ --- [shell~11] Merge branch 'vim-plugin' +*++ [vim-plugin] vim: rnu(relative number unit) ์ ๊ฑฐ
-
shell branch์์ ์คํ ๊ฒฐ๊ณผ
! [git] /Users/nephilim/.dotfiles/git/bin ์ ๋ฆฌ ! [master] Merge branch 'shell': md2docx added * [shell] shell: md2docx added ! [vim-plugin] vim: rnu(relative number unit) ์ ๊ฑฐ
- [master] Merge branch 'shell': md2docx added +* [shell] shell: md2docx added +* [shell^] taskit: help message typo fixed
- [master^] zsh: JAVA_HOME libexec/javahome ์ ์ด์ฉํ์ฌ ๊ฒฝ๋ก ์ค์
+* [shell
2] taskit: weekday(mon, tue, ...) based registration added +* [shell3] choojerk: push notification (via parse.io) added +* [shell4] choojerk: web crawling script for Google I/O +* [shell5] taskit: task list escape added +* [shell6] taskit: tast select & done menu added +* [shell7] taskit: tasklist selection&store menu +* [shell8] google tasks api๋ฅผ ์ด์ฉํ task adder +* [shell9] dev command ์์ ++ [git] /Users/nephilim/.dotfiles/git/bin ์ ๋ฆฌ ++* [shell10] git: git-track-branch ์ถ๊ฐ --- [shell11] Merge branch 'vim-plugin' ++*+ [vim-plugin] vim: rnu(relative number unit) ์ ๊ฑฐ
-
-
---
์ด์ ๋ผ์ธ(header)- ๊ฐ ๋ธ๋์น์ ์ต๊ทผ commit ์์ฝ
- *์ HEAD๋ฅผ ์๋ฏธ, ๋๋จธ์ง๋ !
-
---
์ดํ ๋ผ์ธ- ๊ฐ ๋ธ๋์น ๋ณ ๋ค์ฌ์ฐ๊ธฐ
- ๊ฐ ์ปฌ๋ผ์๋ ํด๋น ๋ธ๋์น๊ฐ ๋๋ฌ ๊ฐ๋ฅํ์ง ์ฌ๋ถ๊ฐ ํ์๋๋ค.
-
merge branch+
branch (other than head-branch)*
current branch
-
- feature๋ ๊ฐ๋ฅํ๋ฉด atomicํ๊ฒ(OCP๋ฅผ ์ง์ผ์), ์๊ฒ ์์ฑํ๋ค.
no-ff
- ๋ ๊ฐ์ ๋ธ๋์น๋ฅผ ๋จธ์ง ํ
- ํ๋๋ฅผ ์ทจ์ํ๋ค
- no-ff๊ฐ ์๋๋ฉด ์ฃผ์ ๋ธ๋์น์ ๋ค์ด์ ์์ด์ ์ ๊ฑฐ๊ฐ ๋ฒ๊ฑฐ๋กญ๋ค
-
๊ทธ๋ ์ง ์๋ค. feature ํค๋๊ฐ ๋จ์์๋ค๋ฉด ํฐ ์ฐจ์ด๊ฐ ์์ง๋ ์๋ค
* e294960 - (HEAD, master, feature-03) feature-03:01 added (36 minutes ago) | * ada416f - (feature-01) feature-01:03 added (46 minutes ago) | * a54c138 - Merge branch 'master' into feature-01 (47 minutes ago) | |\ | |/ |/| * | 247ab63 - Merge branch 'feature-01' (50 minutes ago)
-
์ master ๋ธ๋์น์์ reset --hard HEAD^ ํด๋ feature-03์ด ๋จ์์๋ค.
-
back-merge
-
back-merge๋ฅผ ํ์ง์๋๋ค.
- feature๊ฐ ์ถฉ๋ถํ ๋ ๋ฆฝ์ ์ด์ง ์๋ค๋ smell
- cherry-pick์ ๊ณ ๋ คํด๋ณธ๋ค
- feature
-
์ฌ๋ก
-
back-mergeํ ์ด๋ ฅ์ด ์๋ feature-01์ ์ ๊ฑฐํ๋ ค๋ฉด?
* 27ad9e1 - (HEAD, master) Merge branch 'feature-01' (10 minutes ago) |\ | * ada416f - (feature-01) feature-01:03 added (21 minutes ago) | * a54c138 - Merge branch 'master' into feature-01 (22 minutes ago) | |\ * | | e294960 - (feature-03) feature-03:01 added (11 minutes ago) | |/ |/| * | 247ab63 - Merge branch 'feature-01' (25 minutes ago) |\ \ | |/ | * 08f01db - feature-01:02 added (46 minutes ago) | * 40577b5 - feature-01:01 added (47 minutes ago) * | 1f3d63c - Merge branch 'feature-02' (35 minutes ago) |\ \ | |/ |/| | * 9140660 - (feature-02) feature-02:01 added (36 minutes ago) |/ * 6f026d1 - initial commit (53 minutes ago)
-
merge ์ทจ์์ ๋ํ ์ฃผ์ ๋ฒ์น(03์ ์ฌํ์ธ)
- ๋๊ตฌ๊ฐ์๊ฒ merge ๋นํ commit object๋ ์ฝ๊ฒ ์ทจ์๊ฐ ๋์ง ์๋๋ค.
- ์๋์ ๋ด์ฉ์ ์ํฅ์ ์ฃผ์๊ธฐ ๋๋ฌธ์ ์๋ ๋ํ ์์ ์ ํด์ผํ๋ค.
- ๋๊ตฐ๊ฐ๋ฅผ mergeํ commit object๋ ์ทจ์ํ ์ ์๋ค.
- ์๋์ ๋ด์ฉ์ ์ํฅ์ ์ค ๊ฑด ์๋๊ธฐ ๋๋ฌธ์ merge commit์ ์ทจ์ํ๋ฉด ๋๋ค.
- ๋๊ตฌ๊ฐ์๊ฒ merge ๋นํ commit object๋ ์ฝ๊ฒ ์ทจ์๊ฐ ๋์ง ์๋๋ค.
-
ํด๋ณด๋
- back-mergeํ feature์ ๋ด์ฉ์ ์ง์คํ์ง ์๊ณ master๋ธ๋์น์ ๋ด์ฉ์ ์์ ํ์ฌ feature์ ์ ์งํ๋ค๋ฉด ํ์คํ ์ ๊ฑฐ๊ฐ ์๋ ๊ฒ์
- ์๊ฒฉ์ ํผํด๋ฅผ ์ค๊น?
- rebase ์์ ์ back-merge๋ฅผ ํ์ง ์์๋ ๊ฒฐ๊ตญ ์ ์ฌ
- TODO: revert๋ก merge ์ทจ์ ์์ ์๋
-
-
share
- integration ์ conflict๋ ๋๋ฌด๋๋ ์์ฐ์ค๋ฌ์ด ํ์(a fact of life)
- fetch, pull, push๋ฅผ hookingํ์ฌ
- rerere
- reuse recorded resolution
- .git/rr-cache์ ์ ์ฅ๋จ
- ์ถฉ๋ ์ ์ฒ๋ฆฌํ (์๋ณธ) ๋ด์ฉ์ ๊ธฐ๋กํจ
git flow์์ ์ฐจ์ด
- git flow์ ๊ฒฝ์ฐ
- dev branch์ ์ปค๋ฐ์ด ๊ฐ๋ฅํจ
- feature๋ก back-merge๋ฅผ ํ๋ฝํจ
DAG
- directed acyclic graph
practice
back-merge
- cherry-pick
- A reasonable middle-ground is cherry-picking.
- ์ด์ :
- ๋ค๋ฅธ feature๊ฐ back-merge์ ํผํฉ๋์ด ์ ์ ๋ ์ ์๋ค.
- ์ ์ ํ ์์ ๊น์ง ๋์๋ค๋ฉด ๋์ฑ ์ต์
our own process
-
feature๋ ๋ ๋ฆฝ์ ์ผ๋ก, dev๋ฅผ ์งํ ์ค์ธ feature์ ๋ฐ์ํ์ง ์๋๋ค. ํนํ, back-merge๋ ํ์ง ์๋๋ค. ๊ตณ์ด ํ์ํ๋ค๋ฉด dev์ ์ํ๋ commit์ cherry-pick ํ๋ค. ๋์์ผ๋ก ๋ํ๋ด๋ฉด ๋ค์๊ณผ ๊ฐ๋ค.
git merge --no-ff
์ฌ์ฉ์ ์ ์ํ์.d-------------d(dev) \ / \ f----f----f f--f(feature) d-------------d(dev) \ / f----f----f---f--f(feature)
์ฐธ๊ณ ๋ก git-flow ๋ชจ๋ธ์์๋ ๋ค์์ ํ์ฉํ๋ค. ํ์ง๋ง ์์ ํํ๋ก ์ ์ง๋๋ ๊ฒ์ด ์ข๋ค.
d---d1---d2---d(dev) \ / \ f-----f----f f--f(feature)
back-merge๊ฐ ํ์ฉ๋๋ ๊ฒฝ์ฐ ๋ค์๊ณผ ๊ฐ์ tree๊ฐ ๋๋ค. ์ด๋ฐ ์์ผ๋ก feature๊ฐ ๊ด๋ฆฌ๋๋ฉด, ํฅํ ํน์ feature๋ฅผ ์ ๊ฑฐํ ๊ฒฝ์ฐ ์์ ์ด ๋งค์ฐ ๊น๋ค๋ก์ ์ง๋ค. back-merge ํ feature์ dev์ ๋ด์ฉ์ด ๋ฐ์๋๋ฏ๋ก dev์์ ์ ๊ฑฐ๋ฅผ ํ ์๊ฐ ์๋ค.
d---d1---d2---d(dev) \ / \ f-----f----f---f---f(feature)
๋ค๋ฅธ ์ด๋ค์ด feature๋ฅผ ์์ ํ๊ณ ์์ง ์๋ค๋ฉด ๋ค์๊ณผ ๊ฐ์ ํํ๋ก rebase๋ ๊ฐ๋ฅํ๊ฒ ์ง๋ง, ๊ถ๊ณ ํ์ง ์๋๋ค.
d--d--d--d(1.6, master) \ f--f--f (feature)
-
feature ๋ธ๋์น ๋ช
- ๊ด๋ จ issue/ticket์ด ์๋ค๋ฉด ํด๋น id๋ฅผ
[id] commit message
์ ํํ๋ก ๊ธฐ์ - ๊ณต๋ฐฑ์ด ์์(
-
์ผ๋ก ๋์ฒด)
- ๊ด๋ จ issue/ticket์ด ์๋ค๋ฉด ํด๋น id๋ฅผ
-
commit message
dangling object
-
๊ฐ๋
- dangling blob๊ณผ dangling commit
-
์ค์ต: check dangling object
-
TODO: ์์ git commit --amendํ unreachable object๋ฅผ ํ์ธํ๋ฉด ์ด์ commit ํ์ธ ๊ฐ๋ฅ
-
TODO: ๋ธ๋์น ์ญ์
* 9e820d4 - (HEAD, master) sample markdown document added (4 seconds ago) | * d9fe5bf - (develop) chapter-06 early translate: done (15 minutes ago) | * 984957a - sample formmated-markdown document added (71 minutes ago) |/ * 878d836 - .git ignore added (73 minutes ago) * 311f263 - (origin/master, origin/HEAD) Initial commit (2 weeks ago)
-
-
git fsck
- Verifies the connectivity and validity of the objects in the database
- ๊ทธ๋ฅ fsck ํ๋ฉด ์ง์์ง ๋ธ๋์น์ commit object๊ฐ ๋์ค์ง ์๋๋ค.
- --no-reflogs ๋ด์ฉ ์ฐธ๊ณ
- --no-reflogs
- reflog์์๋ง ๋๋ฌํ ์ ์๋ ๊ฒ์ ๋๋ฌ๊ฐ๋ฅ์ด๋ผ ๊ณ ๋ คํ์ง ์๋๋ค๋ ์๋ฏธ
-
- TODO: ์์ git commit --amendํ unreachable object๋ฅผ ํ์ธํ๋ฉด ์ด์ commit ํ์ธ ๊ฐ๋ฅ
- --unreachable
- reference ๋ ธ๋(reflogํฌํจ)์์ ๋๋ฌํ ์ ์์์ ์๋ฏธ
- unreachable object์ ํ์ธ
-
--no-reflogs์ ํจ๊ป ์ฌ์ฉํ๋ฉด ์ฌ๋ผ์ง ๋ธ๋์น๋ฅผ ํ์ธํ ์ ์๋ค
> git fsck --unreachable --no-reflogs Checking object directories: 100% (256/256), done. unreachable blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 unreachable commit 984957a17d27b0984f0b390c8a50f639698f4d7f unreachable commit d9fe5bf153fb37e14698c76a83b8c2e93ce2f1cf
-
- --dangling
-
๋ง๋ค์ด์ง๊ธฐ๋ ํ์ผ๋, ์ง์ ์ฌ์ฉ๋(์ฐธ์กฐ๋) ์ ์ด ์๋ object
> git fsck --dangling --no-reflogs Checking object directories: 100% (256/256), done. dangling blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 dangling commit d9fe5bf153fb37e14698c76a83b8c2e93ce2f1cf
-
984957a17d27b0984f0b390c8a50f639698f4d7f
์ ๊ฒฝ์ฐ ์์์ด ์์ผ๋ฏ๋ก dangling์์ ์ ์ธ๋๋ค
-
- --full
- .git/object ๋ฟ๋ง ์๋๋ผ packed object, GIT_ALTERNATE_OBJECT_DIRECTORIES๋ฅผ ๋ชจ๋ ๊ฒ์ํจ
-
git gc
- housekeeping tasks
- compressing file revisions
- removing unreachable objects
- gc ๋์์ dangling object๊ฐ ์๋
- --aggresive
- aggresively compress
- ๋์คํฌ ๊ณต๊ฐ์ ์ฌ์ ๊ฐ ์์ด๋ ์์ถ์ ์ํ
- --auto
- gc.auto ๊ฐ์๋ฅผ ๋๋ loose object๋ repack
- git gc --prune=now
- now ์ด์ ์ loose object ์ญ์
- defalut: 2์ฃผ๋ก ์ค์ ๋์ด ์์
- --no-prune: ์์ถ๋ง
- now ์ด์ ์ loose object ์ญ์
- config
- gc.pruneexpire
- gc.reflogexpire
- gc.reflogexpireunreachable
- ๋ค๋ฅธ git command์์ ํ์ฉํจ
- gc.auto ์ค์
- git config --global gc.auto 0
- gc.auto ์ค์
- housekeeping tasks
-
git prune
- remove unreachable objects
-
git reflog
- git reflog expire --expire=now --all
-
exampleA
git reflog expire --expire=now --all # will now report unreachable git reflog # nothing to print out git fsck --unreachable # will now actually delete objects git prune -v # gives "bad object ..." git show $dead_commit
notes
- git notes add
- notes are stored only in local repo
- don't change history
- share notes
- use-cases
- notes are stored only in local repo