Git 恢复本地提交

发布于 2024-11-16 02:38:39 字数 134 浏览 1 评论 0原文

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

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

骄兵必败 2024-11-23 02:38:39
git reset --hard remotes/origin/HEAD
git reset --hard remotes/origin/HEAD
庆幸我还是我 2024-11-23 02:38:39
git reset --hard remotes/origin/YOUR/BRANCH

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

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

better than /HEAD because you won't see this:

$ git status
On branch MY/BRANCH
Your branch and 'origin/MY/BRANCH' have diverged,
and have 1 and 1 different commit each, respectively.
oО清风挽发oО 2024-11-23 02:38:39

来恢复本地提交

git reset HEAD~N

您可以通过使用 N ,以恢复提交数量。一个例子:

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

git reset HEAD~1


git 重置 HEAD^

You can revert local commit by

git reset HEAD~N

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

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

git reset HEAD~1

or
git reset HEAD^

小糖芽 2024-11-23 02:38:39

如果您确信这一点并且没有任何本地未提交更改:

git reset --hard origin/master

其中origin/master是您推送到的分支。

引用日志仍将包含恢复的位,直到垃圾收集使它们过期。要恢复恢复,

git reset --hard HEAD@{1}

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

git reset --hard origin/master

where origin/master is the branch you had pushed to.

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

git reset --hard HEAD@{1}
墟烟 2024-11-23 02:38:39

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

删除/恢复本地提交;

git reset HEAD~{number_of_commit}

简而言之,您在命令提示符下点击 git log 并获取提交列表。看看您现在创建了多少提交以及需要恢复多少提交。

例如,您必须删除并恢复最后两次提交,然后点击

git reset HEAD~2

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

命令是:

git reset --hard remotes/origin/HEAD

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 log on 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.

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文