2016-02-08 113 views
0

對於問這個問題,我已經提前道歉了,因爲它已經被問過一百萬次了。修改github的歷史

我需要修改我的項目的git的歷史, 提交歷史目前看起來是這樣的:

[E] <- [D] <- [C] <- [B] <- [A] 

其中: 答:添加一些代碼, B:增加了一些代碼&增加了一些數據, C:重組項目, d:刪除所有數據, E:增加了一些代碼

的問題是,在提交ç我們的項目組被告知,數據必須保存的I而不是在git上公開。我對git並不是很有經驗,所以我做的第一件事就是刪除數據。但是由於這些數據仍然可以在歷史中被訪問,所以沒有做太多的工作。我該如何解決這個問題,這樣的歷史是這樣的:

[E] <- [C] <- [B] <- [A] 

其中: 答:添加一些代碼, B:增加了一些代碼, C:重組項目(無數據的任何引用) E:增加了一些代碼

+1

注意,任何回答你將需要力推,這將反過來要求大家誰擁有在本地計算機上此回購做一些東西,以及刪除提交D. –

回答

4

這裏有一個方法來刪除特定的承諾,如果從歷史

git的變基--onto提交-ID提交-ID頭

你可以使用以下命令來刪除承諾 「d」 從歷史

git的變基--onto DE HEAD

+0

好了,但有一個以某種方式編輯提交的方式? –

+0

你有沒有試過git commit --amend?它允許你編輯提交。 – SnehalK

+0

我相信它應該是'git rebase - 去E D HEAD'。此外,這需要推動力量。 –

1

你可以用以下命令做到這一點:

# Rebase from C commit in interactive mode... 
git rebase -i C 

# Then remove the D commit line in the editor, save and quit. 
# You can edit commit messages by using "edit" option for 
# concerned commits. 
# Resolve conflicts if needed and finish rebasing. 

OR(不提交信息編輯):

# Rebase from C: Pick E history but exclude D history 
git rebase --onto C D E 

然後,你將不得不推動修改(帶來的所有麻煩,它可以導致...)。

# --force-with-lease means: 
# "If anybody already pushed after the last known origin/<branch> sha1, 
# The push force command will be aborted (avoids to loose newers pushes 
# from your friends...). 
git push --force-with-lease origin <branch>