Jim Chen: Splitting a Git commit into two |
Oftentimes I make a big commit that I later realize should be split into two commits/patches. I think the usual way to split a Git commit is the reset/“add -p”/commit sequence, like this,
# assuming HEAD is the commit to split, git reset HEAD^ # first undo the commit git add -p # then choose bits to separate out git commit # commit separated changes git commit -a # commit other changes
But lately I've been using another way that involves a “commit –fixup”/revert/“rebase -i” sequence, like this,
# assuming HEAD is the commit to split, # first, in Your Favorite Editor, delete everything that you want to separate out git commit -a --fixup HEAD # then commit the changes you removed as a fixup git revert -e HEAD # revert the fixup; this will become the split commit git rebase -i --autosquash HEAD~3 # combine the original commit and the fixup
One thing I like about this second method is that it lets me pick out the changes to separate out in an editor with full context. I think this is a lot better than git add -p
, which involves editing the hunks directly, and sometimes provides too little context to let me determine if a particular hunk should be separated out or not.
http://www.jnchen.com/blog/2014/03/splitting-a-git-commit-into-two
Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |