2009-08-20 51 views
2

我必須重寫我的存儲庫的歷史記錄,因爲它包含一些憑證。因爲我有修改根犯我跟着從Git Faq說明:Git,編輯所有分支的根提交

git rebase -i可以讓你方便地編輯任何以前提交,除了根提交。以下命令顯示如何手動執行此操作。

# tag the old root 
git tag root `git rev-list HEAD | tail -1` 
git checkout -b new-root root 
# edit... 
git commit --amend 

# check out the previous branch 
git checkout @{-1} 
# replace old root with amended version 
git rebase --onto new-root root 

# cleanup 
git branch -d new-root 
git tag -d root 

我的問題是,雖然我在倉庫中有兩個分支,幾個​​標籤已經和我想的是我的歷史改寫適用於這些了。回購尚未公開,所以這不成問題。我之前詢問過similar question,但在這種情況下,沒有使用git rebase命令。這裏是我的回購協議的基本圖形:

+ master branch 
| 
| + topic branch 
| | 
| | 
+---+ 
| 
| 
| 
+ TAG 
| 
+ Initial commit, the commit I'd like to amend for all branches 

它甚至有可能?

+0

可能相關:[編輯/修改/修改/更改Git中的第一個/根/初始提交?](http://stackoverflow.com/q/2119480/456814)。 – 2014-05-15 08:47:24

回答

6

使用git filter-branch而不是git-rebase。

如果你真的覺得衍合會更好,擁有現代化的git你可以使用--root選項混帳底墊。或者櫻桃挑選根提交,然後重新綁定它,如果你有舊的git沒有這個選項。

+0

謝謝Jakub。但我不確定'filter-branch'會如何幫助我。我必須編輯近10個文件中的代碼,以便我假裝第一次提交沒有證書。我不知道這會怎麼樣,因爲這些文件沒有標準格式。這只是代碼。我認爲可以使用'--tree-filter',但似乎很難解析代碼。 – 2009-08-20 18:28:30

+2

如果是這種情況,最簡單的解決方案是創建一個新的空分支('git symbolic-ref HEAD refs/heads/new && rm -f .git/index'),然後在該分支上進行櫻桃挑選根提交,編輯它使用'git commit --amend',然後rebase休息,或者使用'git rebase --interactive --root - to new master'。 HTH。 – 2009-08-20 22:13:32

+0

謝謝,我會嘗試他們兩個,雖然第二個選項似乎更容易。不勝感激。 – 2009-08-21 08:10:04