简体   繁体   English

如何将本地和远程 git 存储库恢复到以前的提交?

[英]How to revert both local and remote git repository to a previous commit?

I want every commit after the one with hash ac9edf2 to disappear entirely from my local repository and the one on Github.我希望 hash ac9edf2之后的每个提交都完全从我的本地存储库和 Github 上的提交中消失。

Trying to following instructions based on previous answers is like trying to study arcane magic.尝试根据先前的答案遵循说明,就像尝试研究奥术魔法一样。 For each step forward I run into a new error, or make some unwanted change I did not intend because the instructions are confusing, and commands are not intuitively named.对于前进的每一步,我都会遇到一个新错误,或者进行一些我不打算进行的不必要的更改,因为说明令人困惑,并且命令的命名不直观。

I just want something to copy and paste into the command line so that I can rewind reality 3 hours ago (specifically, to that commit) so that neither my local harddrive or the Github website knows about the alternate universe where I made commits after ac9edf2 .我只想将一些内容复制并粘贴到命令行中,以便我可以倒回 3 小时前的现实(特别是那个提交),这样我的本地硬盘驱动器或 Github 网站都不知道我在ac9edf2之后提交的备用宇宙。

And I need it to be such that after I copy and paste these commands into the command line and hit ENTER, I can resume committing via MSVSC as usual, and be able to press CTRL + G then click Publish branch as usual to upload my new commits to Github without getting any deadly fatal errors.我需要这样,在我将这些命令复制并粘贴到命令行并按 ENTER 后,我可以像往常一样通过 MSVSC 继续提交,并且能够按CTRL + G然后像往常一样单击Publish branch以上传我的新分支提交给 Github 而不会出现任何致命的致命错误。

I don't want to become a git expert.我不想成为 git 专家。 I don't need to be concerned about any non-existent collaborators losing their work.我不需要担心任何不存在的合作者失去他们的工作。 I just want to go back in time to the commit ac9edf2 .我只想及时将 go 退回到提交ac9edf2 Forever.永远。

On your local machine, with your master branch checked out (presumably that's what you want to fix up, right?):在您的本地机器上,检查您的主分支(大概这就是您想要修复的,对吧?):

$ git reset --hard ac9edf2
$ git push -f

This answer does assume that your local branch is checked out as a tracking branch.此答案确实假定您的本地分支已作为跟踪分支签出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM