在其他平臺上使用gitk(* nix)或gitx(OS X)或類似軟件,並查看哪些提交是分支的根。然後運行:
git rebase -i <the SHA hash of the root commit>
例如,我有我使用gitx檢查存儲庫:
gitx screencap http://img.skitch.com/20081213-mq7qpp5nhceksdhfx14rerjgyx.jpg
現在我知道了根散列我可以運行此:
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
它會顯示你的那個分支的所有提交和管道貓將禁用尋呼機,所以你看到的第一個立即提交。
編輯:組合上述給出了一個完全自動化的解決方案:
git rebase -i `git log master..other_feature --pretty=format:"%h" | tail -n 1`~
請標題你的問題好一點。也許提到你想爲分支中的所有更改做一個交互式重新分配。最好以問題的形式(儘管並非總是可行)。 – Dustin 2008-12-12 20:58:12
你想重新綁定到一個修改過的`master`上,或者只是編輯剛剛在`test-branch`上做出的提交? – DylanYoung 2017-11-10 18:12:23