简体   繁体   English

如何恢复到当前对git提交的开始?

[英]How do I revert to the beginning of my current commit on git?

I know how to revert to previous commit. 我知道如何还原到先前的提交。 But now I did a lot of work since I committed and I want to restart and start from scratch straight from my current commit. 但是自从我提交以来,现在我做了很多工作,我想从当前提交中重新开始并从头开始。

How do I do that? 我怎么做?

git reset --hard is the easiest one... but it does get rid of everything that's hanging around. git reset --hard是最简单的方法...但是它确实摆脱了所有悬而未决的问题。 You might also consider just saving it in the stash and dump it later on when you are sure you won't need it anymore. 您可能还考虑将其保存在存储中,并在以后确定不再需要它时将其转储。

git stash push -m "Saving this in case I want to use it later on"

That will clean up the working tree. 这将清理工作树。

HEAD引用了当前分支中的最新提交,您可以将其git resetgit reset

$ git reset HEAD --hard

If you have created new files or directories that you need to get rid of, you can also use git clean -fd to remove those. 如果创建了需要删除的新文件或目录,则还可以使用git clean -fd删除这些文件或目录。

To revert changes in tracked files you can do git reset --hard which will remove all new code since your last commit. 要还原跟踪文件中的更改,您可以执行git reset --hard ,它将删除自上次提交以来的所有新代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM