如何在git中回到以前的版本 [英] How to go back to previous version in git

查看:208
本文介绍了如何在git中回到以前的版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作站中有一个远程git仓库的结帐副本。
我意外地在我的本地进行了更改,并将其推送到远程。
现在我想删除最后一个提交并返回到前一个提交,同样应该推送到远程。

I have a checkout copy of a remote git repository in my workstation. I have accidentally committed a change in my local and pushed to remote. Now I want to remove the last commit and go back to the previous commit and the same should be pushed to remote.

如果它是一个提交消息的新提交。如何做到这一点?

I am okay if it is a new commit with a commit message. How to do that?

推荐答案

我建议不要使用 - 强制替代历史记录进行推送。
任何已经完成修改的人都会有一个完全无法理解的历史记录来处理新东西。

I'd advise against pushing with --force an alternative history. Anyone who already pulled your changes will have a completely screwed history to deal with when pulling new stuff.

更安全的方法是简单地执行

A far safer option is to simply do

git revert HEAD~1 
git push origin master

git revert 会记录一个新的提交,取消前一个

git revert will record a new commit that cancels all of the effects of the previous one

这篇关于如何在git中回到以前的版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆