GIT:恢复上次提交?
我应该使用哪个命令来恢复上次提交所做的更改?提交已被推送到远程服务器。
Which command do i use to revert the changes made by the last commit? The commit was already pushed to the remote server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这将撤销最近的提交。然后只需将其向上推即可。
您可以将
HEAD
替换为您想要的修订版本。That will back out the most recent commit. Then just push it up.
You can replace
HEAD
with the revision you want out.这取决于你所说的恢复是什么意思。您想要执行“真正的”恢复,即创建与您想要恢复的提交完全相反(差异)的另一个提交,或者完全忘记该提交。
在第一种情况下,如上所述:
git revert HEAD
。在提交消息中,提及恢复的原因。然后推送结果。在第二种情况下,
git reset --hard HEAD~1
。但是,您需要用力推动。如果您位于master
分支(并且您的远程称为origin
),则为git push origin +master
。It depends what you mean by reverting. You want to either do a "real" revert, ie creating another commit which is the exact opposite (diff-wise) of the commit you want to revert, or completely forgetting about the commit.
In the first case, as mentioned:
git revert HEAD
. In the commit message, mention the reason for the revert. Then push the result.In the second case,
git reset --hard HEAD~1
. However, you'll need to force the push. If you're on branchmaster
(and your remote is calledorigin
), that would begit push origin +master
.