简体   繁体   English

将git repo恢复为先前的提交

[英]Revert git repo to previous commit

I have a git problem. 我有一个git问题。 I develop on my local host, push changes to my repo, then pull to my live site. 我在本地主机上开发,将更改推送到我的存储库,然后拉到我的实时站点。 I recently built a page on my localhost, which worked fine. 我最近在本地主机上构建了一个页面,该页面运行良好。 Then I pushed to my repo and pulled to the live site. 然后,我推送到我的仓库,然后转到现场。 For some reason the changes broke my live site. 由于某种原因,这些更改破坏了我的实时站点。 For example purposes, here are the hashes of the broken commit and the working commit: 出于示例目的,这是断开提交和工作提交的哈希值:

ABCDE 'This commit works on the local host and the live site' ABCDE'此提交适用于本地主机和实时站点'
ZYXWV 'This commit works on local host but not live site' ZYXWV'此提交在本地主机上有效,但在实时站点上无效'

So I made the commit ZYXWV on my local host and pushed it to the repo. 因此,我在本地主机上进行了提交ZYXWV并将其推送到存储库中。 Then I pulled ZYXWV to my live site, which broke it. 然后我将ZYXWV拉到我的活动站点,这使它损坏了。 In order to fix my live site I did the following: 为了修复我的实时网站,我做了以下工作:

git checkout ABCDE git checkout ABCDE

So, now my live site is working. 因此,现在我的实时站点正在运行。 The only problem is that my live site is not in sync with my repo, which means I can't pull any changes without getting the broken code. 唯一的问题是我的活动站点与我的仓库没有同步,这意味着我不能在没有损坏代码的情况下进行任何更改。 I don't need the broken code and am okay if it gets deleted. 我不需要损坏的代码,并且可以删除它。 I just need a way to get the repo in sync with ABCDE again. 我只需要一种使存储库与ABCDE再次同步的方法。

I hope that made sense. 我希望这是有道理的。 I am not that great with git. 我对git不太满意。 Thanks for your help. 谢谢你的帮助。

It sounds like you may want to do this 听起来您可能想这样做

git revert ZYXWV

This will create a new commit reverting the commit that is not working on the live site. 这将创建一个新的提交,以还原不在实时站点上工作的提交。 Now you can pull this to the live site and do git checkout master . 现在,您可以将其拉到实时站点并执行git checkout master

Then you could proceed and try to recreate a better commit than ZYXWV that will work everywhere. 然后,您可以继续尝试重新创建比ZYXWV更好的提交,该提交可以在任何地方使用。

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

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