2014-12-02 33 views
-1

我最近在github上對一個開源項目做出了貢獻,它很受歡迎,但我不符合提交消息標準,所以我被要求這樣做,而是對每次提交做一次更改,我只需要對其中提出的所有更改作出承諾。取消幾次提交只有一個在git

那麼,我怎樣才能撤消我以前的所有提交,並只做一個包含所有更改的提交?

+2

可能重複http://stackoverflow.com/questions/5189560/squash-my-last-x-commitits-together-using-git) – 2014-12-02 02:26:09

+0

你能指定項目的所有者是否已經回滾你的提交嗎?如果是這樣,您可以簡單地將您的功能分支合併到遠程。然後你會留下一個提交一個評論。 – 2014-12-02 09:08:35

回答

1

你可以使用git interactive rebase來「擠壓」你的提交到一個。

# To squash 2 commits 
git rebase -i HEAD~2 

# To squash back to a specific commit identified by it's sha1 
git rebase -i a3ea79f 


如果你有一個提交歷史是這樣的: - 以上

git log --oneline --decorate 

* d6f7bbd (HEAD, master) added test2 
* 35dde7a added test1 
* a3ea79f initial commit 


衍合與任一底墊的命令,將打開編輯器。它會是這個樣子,並修改「選擇」線將調整提交: -

pick 35dde7a added test1 
pick d6f7bbd added test2 

# Rebase a3ea79f..d6f7bbd onto a3ea79f 
# 
# 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 
# 
# 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 
[壁球我最後的X犯下一起使用Git(的