2014-05-19 166 views
1

我想從GitHub上提交歷史記錄中刪除一些提交。如何從GitHub上的提交歷史中刪除提交?

不過,我不希望實際刪除與特定提交相關的代碼。我只想刪除提交歷史中出現的提交。這可能嗎?如果是這樣,怎麼樣?

謝謝!

+1

也許變基並壓扁違規提交到另一個呢? – pdobb

+0

謝謝pdobb!謹慎展示一個例子,因爲這樣會更容易。 – user3399101

回答

1

你需要的是南瓜的提交。

你想看看到this article有更多的信息

試想一下,你有,你要轉換成1 3個提交,因爲所有的人都應該是真的一個單一的承諾,所以你想擁有新功能提交和許可證提交。他們似乎以相反的順序(第一個承諾是最古老的)

您通過衍合當前分支

$ git rebase -i HEAD~4 

pick 9420b31 New feature 
pick 8414d83 Adding license to code 
pick 7bfb349 More info into the license 
pick c79e70f Fixing license 

# Rebase 93275f0..9420b31 onto 93275f0 
# 
# 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 
# 

開始,然後更改許可從「撿」來「修正」(如果你想提交丟棄提交消息)或「壓扁」(如果你需要保留它)。

在這個例子中,這將成爲

$ git rebase -i HEAD~4 

pick 9420b31 New feature 
pick 8414d83 Adding license to code 
fixup 7bfb349 More info into the license 
fixup c79e70f Fixing license 

# Rebase 93275f0..9420b31 onto 93275f0 
# 
# 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 
# 

之後,你將有隻有兩個提交:一個添加該功能,以及一個添加許可證(但是,代表證的散列承諾將改變)。

只要一注:如果您已經被推歷史進入一個遠程服務器,則可能需要「推--force」他們。如果有人克隆了回購,他們在更新時可能會遇到問題(衝突)。

相關問題