使用反向补丁推送后撤消 Git 提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6441902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:13:56  来源:igfitidea点击:

Undo a Git commit after push using reverse patch?

git

提问by Dziamid

I've pushed a commit and I want to revert changes introduced by this commit by applying and committing a reversed patch. How do I do it?

我已经推送了一个提交,我想通过应用和提交一个反向补丁来还原这个提交引入的更改。我该怎么做?

采纳答案by Kris K.

回答by pilif

Use

git revert HEAD

This will create a patch that reverts the last commit and commit that patch as a new commit.

这将创建一个恢复上次提交的补丁并将该补丁作为新提交提交。

If you want to revert a specific earlier version, use

如果要恢复特定的早期版本,请使用

git revert <revision>

see also: http://schacon.github.com/git/git-revert.html

另见:http: //schacon.github.com/git/git-revert.html

回答by Amit

simply use

简单地使用

for committed file:

对于提交的文件:

git revert <SHA1 ID>

for non-committed file:

对于未提交的文件:

git reset --hard HEAD