如何取消提交我在Git中的最后一次提交 [英] How to uncommit my last commit in Git

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

问题描述



是否它是

  git reset --hard HEAD 

  git reset --hard HEAD ^ 

解决方案

如果您不完全确定uncommit的含义并且不知道是否要使用 git reset ,请参阅恢复到之前的Git提交



如果您想更好地理解 git reset ,请参阅




如果您知道要使用 git reset 仍然取决于你的意思是不承诺。如果你想要做的只是撤消提交行为,而保留其他所有内容,请使用:

  git reset --soft HEAD ^ 

如果您想撤销提交的动作以及您上演的所有内容,请将作品树(您的文件完好无损):

  git reset HEAD ^ 

如果您真的想完全撤消它, 抛弃所有未提交的更改,将所有内容重置为前一个提交 (如原问题所述):

  git reset --hard HEAD ^ 






原始问题还要求 HEAD ^ 不是 HEAD HEAD 指的是当前提交 - 通常是当前签出分支的提示。 ^ 是一个可以附加到任何提交说明符的符号,意思是之前的提交。因此, HEAD ^ 是当前提交之前的提交,就像 master ^ 提交之前的提交一样。 master分支。



以下是 ^ )的所有方法的noreferrer> git-rev-parse文档只是很多中的基本代码)。


How can I uncommit my last commit in git?

Is it

git reset --hard HEAD

or

git reset --hard HEAD^

?

解决方案

If you aren't totally sure what you mean by "uncommit" and don't know if you want to use git reset, please see "Revert to a previous Git commit".

If you're trying to understand git reset better, please see "Can you explain what "git reset" does in plain English?".


If you know you want to use git reset, it still depends what you mean by "uncommit". If all you want to do is undo the act of committing, leaving everything else intact, use:

git reset --soft HEAD^

If you want to undo the act of committing and everything you'd staged, but leave the work tree (your files intact):

git reset HEAD^

And if you actually want to completely undo it, throwing away all uncommitted changes, resetting everything to the previous commit (as the original question asked):

git reset --hard HEAD^


The original question also asked it's HEAD^ not HEAD. HEAD refers to the current commit - generally, the tip of the currently checked-out branch. The ^ is a notation which can be attached to any commit specifier, and means "the commit before". So, HEAD^ is the commit before the current one, just as master^ is the commit before the tip of the master branch.

Here's the portion of the git-rev-parse documentation describing all of the ways to specify commits (^ is just a basic one among many).

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

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