回滚到最后的git提交 [英] Rollback to last git commit

查看:149
本文介绍了回滚到最后的git提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是做了一个

  git commit -mblah

然后我添加了一些文件,我该如何回滚并删除当前文件中尚未添加/提交的内容?

解决方案

下面的 ORIGINAL 答案就是我认为的 OP 所寻找的。虽然,根据@ChrisNevill的评论,最初的答案可能不是您 所寻找的。我已经更新了答案以澄清。




→UPDATED ANSWER



<1>对于 UNDO 本地文件更改,但不删除最后一次提交,然后使用

  git reset --hard 



<2> UNDO 本地文件更改 AND REMOVE 您的上次提交,然后使用

  git reset --hard HEAD ^ 

git reset --hard HEAD〜



3)要保留本地文件更改和仅删除最后一次提交,然后使用

  git reset --soft HEAD ^ 

git reset --soft HEAD〜

经常使用 git status git log 来观察您的当前状态。



$ b原始答案
将工作树重置为最后一次提交

  git reset --hard HEAD ^ 

清理工作树中的未知文件

  git clean 


I just did a

git commit -m "blah"

then I added some files, how do I rollback and remove what is in my current files that have not yet been added/committed?

解决方案

The below ORIGINAL answer is what I "think" the OP was looking for. Although, per a comment by @ChrisNevill, the original answer may not be what YOU are looking for. I've updated the answer to clarify.


→ UPDATED ANSWER

1) To UNDO local file changes but NOT REMOVE your last commit, then use

git reset --hard

2) To UNDO local file changes AND REMOVE your last commit, then use

git reset --hard HEAD^
or
git reset --hard HEAD~

3) To KEEP local file changes and REMOVE ONLY your last commit, then use

git reset --soft HEAD^
or
git reset --soft HEAD~

Use git status and git log frequently to observe your current state.


→ ORIGINAL ANSWER

"Reset the working tree to the last commit"

git reset --hard HEAD^   

"Clean unknown files from the working tree"

git clean

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

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