2017-02-20 60 views
1

我在我的分支上有大約10個提交,讓我們說ID 1到10.我想壓縮提交4,5和6在一起,但其餘不變。我找到的每個教程都從當前的HEAD開始,並使用git rebase -i HEAD〜(x數量)向後退出。但是,我如何在早期提交時啓動rebase並指定一個範圍,比如git rebase -i 6 ... 4?我該如何在早些時候一起承擔責任?

謝謝

+0

教程就是這樣,因爲它們必須是。 Rebase *拷貝*提交,原封不動(它必須; Git在提交後不能改變任何東西)。因此,您必須在所有提交之後「重新複製所有提交」,因爲原始的未提交的提交指向他們之前的原始未固定提交。請參閱下面的賈裏德的答案。 – torek

回答

2

只是做一個互動變基,修正的壁球你想擠壓或fixupped(搞掂?)

git rebase HEAD~10

pick a4461d3 
pick d998164 
pick 0a1f6e1 
f 310ba9d 
f 60b7e01 
f 7baef60 
pick bb9a551 
pick badbad1 
pick fd9a10c 
pick 59ed66f 

# Rebase e7e1369..60b7e01 onto fd9a10c (10 command(s)) 
# 
# Commands: 
# p, pick = use commit 
# r, reword = use commit, but edit the commit message 
# e, edit = use commit, but stop for amending 
# s, squash = use commit, but meld into previous commit 
# f, fixup = like "squash", but discard this commit's log message 
# x, exec = run command (the rest of the line) using shell 
# d, drop = remove commit 
# 
# These lines can be re-ordered; they are executed from top to bottom. 
# 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# 
# However, if you remove everything, the rebase will be aborted. 
# 
# Note that empty commits are commented out 
+0

沒有意識到我可以做到這一點。謝謝 – thatDubstepSound

1

好,@jaredr已經回答了提交你的問題。回到問題的第二部分,GIT不提供這樣的命令(git rebase -i 4..6)。實際上它不應該!想象一下,如果GIT開始提供這樣的命令(必須對某些提交執行操作並對其他人進行堆棧操作),必須執行多少操作,正確合併會增加額外的複雜性,因此,它會將此作業傳送給用戶本身/她是更瞭解代碼的人。)此外,它還提供了像Git squash這樣的幫助機制,您可以在其中暫時轉儲提交併處理其他內容。

+0

我不知道你的意思。然而,在完全線性的提交歷史記錄中(假設沒有合併發生),我仍然不知道這會如何增加複雜性。畢竟,我們可以假設3,4,5都是同時發生的,然後繼續向右移動到6? – thatDubstepSound