撤消对git中一个文件的多个提交

撤消对git中一个文件的多个提交,git,github,Git,Github,我最近在github上为一个开源项目做了一个贡献,它很受欢迎,但我不符合提交消息标准,所以我被要求这样做,而不是每次提交都做一个更改,我应该只提交一个包含我在其中提出的所有更改的提交 那么,我如何撤消以前的所有提交,并对其中的所有更改只执行一次提交呢?您可以使用git交互式重基将您的提交“压缩”为一次提交。 # To squash 2 commits git rebase -i HEAD~2 或 如果您有这样的提交历史记录:- git log --oneline --decorate * d

我最近在github上为一个开源项目做了一个贡献,它很受欢迎,但我不符合提交消息标准,所以我被要求这样做,而不是每次提交都做一个更改,我应该只提交一个包含我在其中提出的所有更改的提交


那么,我如何撤消以前的所有提交,并对其中的所有更改只执行一次提交呢?

您可以使用git交互式重基将您的提交“压缩”为一次提交。

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


如果您有这样的提交历史记录:-

git log --oneline --decorate

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

使用上述任意一个rebase命令进行重定基址将打开编辑器。它看起来像这样,修改“pick”行将调整提交:-

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

您能否指定项目的所有者是否已回滚您的提交?如果是这样,您可以简单地将功能分支合并到远程。然后,您将留下一个commit和一个comment。
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