我如何在git中提交提交? [英] How do I reverse a commit in git?

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

问题描述

我并不十分熟悉git的工作方式。我错误地推了一个提交,并想恢复它。我做了一个

  git reset --hard HEAD〜1 

提防Google员工: 这不仅会恢复提交,还会放弃所有文件更改!



现在项目在我的机器上恢复,但不在github上。如果我尝试推送这段代码,我得到错误'你的分支在'origin / master'后面被1提交,并且可以被快速转发。'如何从github中删除这个提交?

$ b $你可以做 git push --force 但是请注意你正在重写历史记录,并且任何人都在使用如果你想防止这个问题,不要使用重置,而是使用 git revert

code>


I'm not really familiar with how git works. I pushed a commit by mistake and want to revert it. I did a

git reset --hard HEAD~1

Beware Fellow Googlers: This does not only revert the commit, but discards all file changes!

and now the project is reverted on my machine, but not on github. If I try to push this code, I get the error 'Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.' How do I remove this commit from github?

解决方案

You can do git push --force but be aware that you are rewriting history and anyone using the repo will have issue with this.

If you want to prevent this problem, don't use reset, but instead use git revert

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

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