2017-08-10 148 views
1

我有SVN歷史約20000個提交。我搬到了Git並保留了歷史。現在我在26000個提交,我想從壓扁1中所有提交至20000壓扁多個歷史提交

  • 初始承諾:a4f5d18
  • 遷移到Git的方法:5a42d81
  • HEAD:933eff

我嘗試檢查出20000,重訂基期:

git checkout 5a42d81 
git rebase squash a4f5d18 

,但我得到:

fatal: Needed a single revision 
invalid upstream squash 

回答

1

如果我理解正確的話,你的主要分支的樣子:

master: 1 -> 2 -> 3 -> .. -> 20000 -> A (First non migrated commit) -> B -> C -> ..

你想獲得到:

master: 1' (All your migrated commits) -> A' -> B' -> C' -> ..

我想你可以遵循使用git rebase HEAD~26000 (first commit hash probably easier)並將pick更改爲squash ,但它可能很費力/費時。

一個潛在可行的解決方案是用你的第一個20000的內容創建一個新的提交。可能值得在備份分支上進行測試。

git checkout <last migrated commit hash> -b backup-master

backup-master: 1 -> 2 -> 3 -> .. -> [20000] -> A (First non migrated commit) -> B -> C -> .. 
             ^- you are here. 

git reset --soft <first migrated commit hash>

backup-master: [1] -> 2 -> 3 -> .. -> 20000 -> A (First non migrated commit) -> B -> C -> .. 
       ^- you are here   ^- the working directory tree/index reflects this commit 

修改您最初提交的內容/消息(或創建一個新的提交如果你願意)。

git commit --amend

現在backup-master應該包含你壓扁的遷移承諾,讓我們繼續前進的新的提交。

git checkout master

git checkout -b master-rebase(以防萬一,我們擺烏龍)。

git rebase backup-master - 我相信這會起作用,因爲git知道成功重新綁定所需的合併。如果這個工作,你應該完成,master-rebase將包含你想要的結果。

如果失敗,則可能有更好的成功與rebase --onto.

git rebase --onto <destination commit> <parent of first desired commit> <last desired commit>

git rebase --onto backup-master <A>~1 master`的

如果這個作品將放置於您提交當前未在任何分支,所以你需要創建一個:

git checkout -b rebase-success

rebase - 的更全面解釋可以找到here

+1

謝謝,這是我一直在尋找的方法,即使實際重新平整速度不會更快,並且與交互式底視圖解決方案不同,您無法看到其進展。注意:我必須在軟重置後創建分支,因爲這會導致分離頭部狀態。 – Qeebrato

+0

啊,這是一個很好的觀點,我忽略了'重置'步驟會讓你分開一個頭。更新了答案,在初始結賬步驟中添加了「-b 」。 – Chris

2

你要多少提交保留,請在下面的命令

git rebase -i HEAD~6000 

該號碼或更準確地說

git rebase -i a4f5d18 

保留6000下方提交(皮克)和改變休息的picksquash

如果rebase成功

git log 

你可以看到你所有的提交南瓜一個承諾

,更好地你推更改遠程,否則當你再次拉你會看到所有的提交。

git push -f 
+0

OP可以使用'a4f5d18'來代替'HEAD〜6000'。 – 1615903

+0

@ 1615903我沒有嘗試,可能是有效的 –

+0

@ThiruShetty我試了一下,它的工作原理 – Qeebrato

0

在所有三種情況下(交互式重置,軟重置,重新綁定),我遇到了空格問題。 Git有嫁接分支的可能性,它發展成替換功能:

git replace -f 5a42d81 a4f5d18 
git filter-branch