在其他平台上使用gitk(* nix)或gitx(OS X)或类似版本,并查看哪个提交是分支的根。然后运行:
git rebase -i <the SHA hash of the root commit>
例如,我有一个使用gitx检查的存储库:

现在,我知道了根哈希,可以运行以下命令:
git rebase -i 38965ed29d89a4136e47b688ca10b522b6bc335f
然后我的编辑器弹出,我可以随意重新排列/压缩/任何内容。
pick 50b2cff File 1 changes.
pick 345df08 File 2 changes.
pick 9894931 File 3 changes.
pick 9a62b92 File 4 changes.
pick 640b1f8 File 5 changes.
pick 1c437f7 File 6 changes.
pick b014597 File 7 changes.
pick b1f52bc File 8 changes.
pick 40ae0fc File 9 changes.
# Rebase 38965ed..40ae0fc onto 38965ed
#
# Commands:
# pick = use commit
# edit = use commit, but stop for amending
# squash = use commit, but meld into previous commit
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
我确信有一种神奇的方法可以说服git自动找出树的根,但是我不知道它是什么。
编辑:魔术是这样的:
git log master..other_feature | cat
这将向您显示该分支上的所有提交,而传递给cat的管道将禁用寻呼机,因此您会立即看到第一个提交。
编辑:结合以上提供了一个完全自动化的解决方案:
git rebase -i `git log master..other_feature --pretty=format:"%h" | tail -n 1`~