2014-12-02 34 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(的