windows Git 还原本地提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6378850/
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-09 08:29:19  来源:igfitidea点击:

Git revert local commit

windowsgitmsysgit

提问by Will

I have a git repo hooked up in phpstorm on windows. I committed a few change sets then pushed them to our "central repo". After this I have then made a few more commits. I no longer want these commits that have not been pushed to the central repo. How do I clean my working copy to be the same as the central repo (origin)?

我在 Windows 上的 phpstorm 中连接了一个 git repo。我提交了一些更改集,然后将它们推送到我们的“中央仓库”。在此之后,我又做了一些提交。我不再想要这些尚未推送到中央仓库的提交。如何清理我的工作副本以与中央仓库(来源)相同?

回答by Steve Prentice

git reset --hard remotes/origin/HEAD

回答by Karl the Pagan

git reset --hard remotes/origin/YOUR/BRANCH

better than /HEADbecause you won't see this:

/HEAD因为你不会看到这个更好:

$ git status
On branch MY/BRANCH
Your branch and 'origin/MY/BRANCH' have diverged,
and have 1 and 1 different commit each, respectively.

回答by sehe

If you feel sure about that and don't have any local uncommittedchanges:

如果您对此感到确定并且没有任何本地未提交的更改:

git reset --hard origin/master

where origin/masteris the branch you had pushed to.

origin/master您推送到的分支在哪里。

The ref-log will still contain the reverted bits, until a garbage collect expires them. To revert the revert,

ref-log 仍将包含恢复的位,直到垃圾收集使它们过期。要还原还原,

git reset --hard HEAD@{1}

回答by uma

You can revert local commit by

您可以通过以下方式恢复本地提交

git reset HEAD~N

where N is used to revert number of commits. An example:

其中 N 用于恢复提交次数。一个例子:

if you have to revert single commit from local, then you can use

如果您必须从本地恢复单个提交,那么您可以使用

git reset HEAD~1

or git reset HEAD^

或 git reset HEAD^

回答by uma

As per my understading, you create some commit that you have pushed on central repo, after that you have create some more commit, but these are exist on local. These all did not push on central repo.

根据我的理解,您创建了一些已推送到中央存储库的提交,之后您又创建了一些提交,但这些提交存在于本地。这些都没有推动中央回购。

To remove/revert local commit;

删除/恢复本地提交;

git reset HEAD~{number_of_commit}

simply, you hit git logon your command prompt and get list of commits. Have a look, how many commit you have created now and how many you have to revert.

简单地说,您点击git log命令提示符并获取提交列表。看一看,您现在创建了多少个提交以及您必须还原多少个。

for example, you have to remove.revert your two last commit then hit

例如,你必须 remove.revert 你的最后两次提交然后点击

git reset HEAD~2

There is one another way to reset your local repo with central repo. But, in this case your local commit will be removed and if other users push commit on central repo then your repo will be updated with that.

还有另一种方法可以使用中央存储库重置本地存储库。但是,在这种情况下,您的本地提交将被删除,如果其他用户在中央存储库上推送提交,那么您的存储库将随之更新。

command is :

命令是:

git reset --hard remotes/origin/HEAD