#TIL #git 이전 commit 쪼개기

  • Start an interactive rebase with git rebase -i <commit>^, where <commit> is the commit you want to split. In fact, any commit range will do, as long as it contains that commit.
  • Mark the commit you want to split with the action “edit”.
  • When it comes to editing that commit, execute git reset HEAD^. The effect is that the HEAD is rewound by one, and the index follows suit. However, the working tree stays the same.
  • Now add the changes to the index that you want to have in the first commit. You can use git add (possibly interactively) or git gui (or both) to do that.
  • Commit the now-current index with whatever commit message is appropriate now.
  • Repeat the last two steps until your working tree is clean.
  • Continue the rebase with git rebase --continue.

- https://git-scm.com/docs/git-rebase

인터렉티브 리베이스(interactive rebase)로 쪼개고 싶은 커밋에 edit 액션을 표시한다. git reset HEAD~1 실행이 핵심. working directory는 그대로 놔두고 HEAD, Index 만 이전 커밋으로 돌린다. 작업 다 하고 이제 커밋해야지~ 이 상태로 된다. 이제 git add . 하지 말고 골라서 stage하고 커밋을 여러 개 만들면 된다.

참고 - #git HEAD, index, working directory 이해하기 - A Tale of Three Trees 발표자료를 보고

Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com

A Random Post