- git fixupμ μ΄μ 컀λ°μ λ΄μ©μ μμ νκΈ° μν νΉμ μ»€λ° μμ± μ΅μ
git rebase --autosquashμ ν¨κ» μ¬μ©νμ¬ μ»€λ° νμ€ν 리λ₯Ό κΉλνκ² μ 리νλ μν¬νλ‘μ°fixup!,amend!μ λμ¬λ‘ λμ 컀λ°μ μλ μλ³νλ λ©μ»€λμ¦
ν΄λΉ κ°λ μ΄ νμν μ΄μ
- μ½λ 리뷰 ν μμ μ¬νμ κΈ°μ‘΄ 컀λ°μ κΉλνκ² λ³ν©νκ³ μΆμ λ
- μ»€λ° νμ€ν 리λ₯Ό λ Όλ¦¬μ λ¨μλ‘ μ μ§νλ©΄μ μ μ§μ μΌλ‘ μμ ν λ
- μλμΌλ‘ interactive rebaseμμ pick β fixup λ³κ²½νλ λ²κ±°λ‘μμ μμ κΈ° μν΄
AS-IS
sequenceDiagram autonumber participant Dev as Developer participant Git as Git Dev->>Git: git commit -m "Add login feature" Dev->>Git: git commit -m "Fix typo in login" Dev->>Git: git commit -m "Add logout feature" Dev->>Git: git commit -m "Fix login validation" Note over Git: νμ€ν λ¦¬κ° μ°λ°μ β<br/>login κ΄λ ¨ μμ μ΄ ν©μ΄μ Έ μμ
TO-BE
sequenceDiagram autonumber participant Dev as Developer participant Git as Git Dev->>Git: git commit -m "Add login feature" Dev->>Git: git commit --fixup HEAD~2 (typo μμ ) Dev->>Git: git commit -m "Add logout feature" Dev->>Git: git commit --fixup HEAD~3 (validation μμ ) Dev->>Git: git rebase -i --autosquash main Note over Git: νμ€ν λ¦¬κ° κΉλ β <br/>"Add login feature" (μμ ν¬ν¨)<br/>"Add logout feature"
μ ν κ°λ : Interactive Rebase
interactive rebase (git rebase -i)λ μ»€λ° νμ€ν 리λ₯Ό λννμΌλ‘ νΈμ§νλ κΈ°λ₯.
git rebase -i HEAD~5 # μ΅κ·Ό 5κ° μ»€λ°μ νΈμ§ λμμΌλ‘ μ΄κΈ°μ€ννλ©΄ μλν°μ todo 리μ€νΈκ° μ΄λ¦Ό:
pick abc1234 feat: Add login
pick def5678 fix: typo
pick ghi9012 feat: Add logout
pick jkl3456 fix: login validation
κ° μ€μ pickμ λ€λ₯Έ λͺ
λ ΉμΌλ‘ λ°κΏ μ μμ:
| λͺ λ Ή | μ€λͺ |
|---|---|
pick (p) | μ»€λ° κ·Έλλ‘ μ¬μ© |
reword (r) | μ»€λ° λ©μμ§λ§ λ³κ²½ |
edit (e) | 컀λ°μμ λ©μΆ°μ μμ κ°λ₯ |
squash (s) | μ΄μ 컀λ°μ ν©μΉκΈ° (λ©μμ§ ν©μΉ¨) |
fixup (f) | μ΄μ 컀λ°μ ν©μΉκΈ° (λ©μμ§ λ²λ¦Ό) |
drop (d) | μ»€λ° μμ |
μ€μ μμλ₯Ό λ°κΎΈλ©΄ μ»€λ° μμλ λ³κ²½λ¨.
μ ν κ°λ : Squash vs Fixup
λ λ€ μ»€λ°μ μ΄μ 컀λ°μ ν©μΉλ λμμ΄μ§λ§ μ»€λ° λ©μμ§ μ²λ¦¬κ° λ€λ¦:
pick abc1234 feat: Add login feature
squash def5678 fix: typo in login
β μλν°κ° μ΄λ¦¬λ©° λ λ©μμ§λ₯Ό ν©μ³μ νΈμ§ κ°λ₯
pick abc1234 feat: Add login feature
fixup def5678 fix: typo in login
β fixup 컀λ°μ λ©μμ§λ μλμΌλ‘ λ²λ¦Ό, μλ³Έ λ©μμ§λ§ μ μ§
| squash | fixup | |
|---|---|---|
| μ½λ λ³κ²½ | ν©μΉ¨ | ν©μΉ¨ |
| μ»€λ° λ©μμ§ | λ λ©μμ§ ν©μ³μ νΈμ§ | μλ³Έ λ©μμ§λ§ μ μ§ |
| μλν° | μ΄λ¦Ό | μ΄λ¦¬μ§ μμ |
| μ©λ | λ©μμ§λ 보쑴νκ³ μΆμ λ | μ‘°μ©ν μμ λ§ λ°μν λ |
μ ν κ°λ : Autosquash
--autosquashλ fixup!, squash!, amend! μ λμ¬κ° λΆμ 컀λ°μ μλμΌλ‘ μ λ ¬νκ³ λͺ
λ Ήμ λ³κ²½ν΄μ£Όλ μ΅μ
.
μλ interactive rebaseμμλ:
- μλν° μ΄λ¦Ό
- fixup 컀λ°μ μ§μ λμ μ»€λ° μλλ‘ μ΄λ
pickβfixupμΌλ‘ μ§μ λ³κ²½
autosquashλ₯Ό μ°λ©΄ μ΄ κ³Όμ μ΄ μ λΆ μλν:
git rebase -i --autosquash main# μλμΌλ‘ μ΄λ κ² μ 리λ¨:
pick abc1234 feat: Add login feature
fixup def5678 fixup! feat: Add login feature β μλ λ°°μΉ + μλ fixup
pick ghi9012 feat: Add logout feature
κΈ°λ³Έκ°μΌλ‘ μ€μ :
git config --global rebase.autoSquash trueμ΄ν git rebase -iλ§ ν΄λ autosquash λμ.
fixupμ 3κ°μ§ λͺ¨λ
1. κΈ°λ³Έ fixup β λ΄μ©λ§ μμ
git commit --fixup=<commit>- λμ 컀λ°μ **λ΄μ©(μ½λ)**λ§ λ³κ²½
- μ»€λ° λ©μμ§λ μλ³Έ κ·Έλλ‘ μ μ§
"fixup! <μλ³Έ μ»€λ° λ©μμ§>"νμμ μ»€λ° μμ±
# μμ: 3κ° μ 컀λ°μ λ²κ·Έλ₯Ό μμ
git add fixed_file.py
git commit --fixup=HEAD~2
# β "fixup! Add login feature" μ»€λ° μμ±2. amend λͺ¨λ β λ΄μ© + λ©μμ§ μμ
git commit --fixup=amend:<commit>- λμ 컀λ°μ λ΄μ©κ³Ό μ»€λ° λ©μμ§ λͺ¨λ λ³κ²½
"amend! <μλ³Έ μ»€λ° λ©μμ§>"νμμ μ»€λ° μμ±- μλν°κ° μ΄λ € λ©μμ§λ₯Ό μμ ν μ μμ
3. reword λͺ¨λ β λ©μμ§λ§ μμ
git commit --fixup=reword:<commit>--fixup=amend:<commit> --onlyμ μΆμ½ν- λμ 컀λ°μ λ©μμ§λ§ λ³κ²½ (stagingλ μ½λ λ³κ²½ 무μ)
- μ½λ λ³κ²½ μμ΄ μ»€λ° λ©μμ§λ§ κ³ μΉκ³ μΆμ λ μ¬μ©
μ 체 μν¬νλ‘μ°
# 1. μΌλ° 컀λ°λ€ μμ±
git commit -m "feat: Add user authentication"
git commit -m "feat: Add dashboard page"
git commit -m "feat: Add profile settings"
# 2. authentication 컀λ°μ μμ μ΄ νμνλ€λ©΄
git add auth_fix.py
git commit --fixup=HEAD~2
# 3. autosquashλ‘ rebase
git rebase -i --autosquash mainrebase todo 리μ€νΈκ° μλμΌλ‘ μλμ²λΌ μ 리λ¨:
pick abc1234 feat: Add user authentication
fixup def5678 fixup! feat: Add user authentication β μλ λ°°μΉ
pick ghi9012 feat: Add dashboard page
pick jkl3456 feat: Add profile settings
λμ μ»€λ° μ§μ λ°©λ²
git commit --fixup=HEAD~3 # 3κ° μ 컀λ°
git commit --fixup=abc1234 # μ»€λ° ν΄μλ‘ μ§μ
git commit --fixup=:/login # "login"μ΄ ν¬ν¨λ κ°μ₯ μ΅κ·Ό 컀λ°