Git Rebase seems to have worked but all commits are still showing in the log… what state am I in?

后端 未结 2 703
谎友^
谎友^ 2020-12-30 11:35

I think I squashed the last 40 commits using rebase. I was following this guide to make sure I didn\'t do anything stupid - http://gitready.com/advanced/2009/02/10/squashing

相关标签:
2条回答
  • 2020-12-30 12:24

    This question is about a slightly surprising aspect of the behaviour of git rebase -i. If you close the editor window without making any changes, then the rebase still takes place.1 (This is very different from the action when the editor for commit messages is popped up, where exiting your editor without making any changes aborts the commit.)

    In your case, since you saved the interactive rebase list elsewhere, and then exited the editor, git assumed that you just want to reapply all those commits as before - it has no way of telling that you saved the file elsewhere. If the history was linear between HEAD and HEAD~40 then the history will be exactly the same (including the object names of each commit), but if it was non-linear you will have rewritten your history so that it's linear (and so will have different object names for some of the commits).

    You might want to check in the reflog that HEAD has the same object name (hash) before and after the rebase to check this.

    1 Although in the version I'm using, if git can tell that the result would be exactly the same it doesn't bother to actually reapply the commits and just puts a single entry in the reflog. However, that optimization clearly hasn't taken place in your situation, since you can see the reapplication of each commit in the reflog.

    0 讨论(0)
  • 2020-12-30 12:31

    If the rebase "todo list" couldn't be saved, your rebase didn't work.

    The easiest way to squash that many commits would be to do git reset --soft HEAD~40 and then git commit with your new message - assuming you want to squash all of them.

    0 讨论(0)
提交回复
热议问题