我试图撤消自上次提交以来发生的所有更改。我在查看后尝试了 git reset --hard 和 git reset --hard HEAD /stackoverflow/questions/7999259/git-how-to-perform-the-tfs-equivalent-of-undo-pending-changes\">这篇文章。我现在回复的头是18c3773 ...但是当我看到我的本地源时,所有的文件仍然存在。我错过了什么?
解决方案
-
git add :
git reset -
这将恢复所有本地未提交的更改(应以repo root身份执行):
git checkout。您也可以将未提交的更改仅恢复到特定文件或目录:
git checkout [some_dir | file.txt]还有另一种方式来恢复所有未提交的更改(更长的输入,但可以从任何子目录中运行):
git reset --hard HEAD -
这将删除所有本地未跟踪文件, / em> git跟踪的文件仍然存在:
git clean -fdx警告:
总结一下:执行下面的命令基本上等于fresh git clone from original source(但它不会重新下载任何东西,所以速度要快得多):
git reset git checkout。 git clean -fdx这个的典型用法是在构建脚本时,必须确保你的树是绝对干净的 - 没有任何修改或本地创建的对象文件或构建工件,并且你想让它工作得非常快,并且不会每次都重新克隆整个存储库。
I'm trying to undo all changes since my last commit. I tried git reset --hard and git reset --hard HEAD after viewing this post. I responds with head is now at 18c3773... but when I look at my local source all the files are still there. What am I missing?
解决方案This will unstage all files you might have staged with git add:
git resetThis will revert all local uncommitted changes (should be executed in repo root):
git checkout .You can also revert uncommitted changes only to particular file or directory:
git checkout [some_dir|file.txt]Yet another way to revert all uncommitted changes (longer to type, but works from any subdirectory):
git reset --hard HEADThis will remove all local untracked files, so only git tracked files remain:
git clean -fdxWARNING: -x will also remove all ignored files!
To sum it up: executing commands below is basically equivalent to fresh git clone from original source (but it does not re-download anything, so is much faster):
git reset git checkout . git clean -fdxTypical usage for this would be in build scripts, when you must make sure that your tree is absolutely clean - does not have any modifications or locally created object files or build artefacts, and you want to make it work very fast and to not re-clone whole repository every single time.
更多推荐
git撤消所有未提交或未保存的更改
发布评论