Break a previous commit into multiple commits

前端 未结 14 2097
渐次进展
渐次进展 2020-12-20 13:09

Without creating a branch and doing a bunch of funky work on a new branch, is it possible to break a single commit into a few different commits after it\'s been committed to

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-20 13:30

    It's been more than 8 years, but maybe someone will find it helpful anyway. I was able to do the trick without rebase -i. The idea is to lead git to the same state it was before you did git commit:

    # first rewind back (mind the dot,
    # though it can be any valid path,
    # for instance if you want to apply only a subset of the commit)
    git reset --hard  .
    
    # apply the changes
    git checkout 
    
    # we're almost there, but the changes are in the index at the moment,
    # hence one more step (exactly as git gently suggests):
    # (use "git reset HEAD ..." to unstage)
    git reset
    

    After this you'll see this shiny Unstaged changes after reset: and your repo is in a state like you're about to commit all these files. From now on you can easily commit it again like you usually do. Hope it helps.

提交回复
热议问题