我试图撤销自上次提交以来的所有更改。在看完这篇文章后,我尝试了git reset -hard和git reset -hard HEAD。我回复头部现在在18c3773…但当我查看我的本地资源时,所有的文件都还在那里。我错过了什么?


当前回答

另一个选项是取消未提交的更改:

git restore <file>

丢弃工作目录中的更改。

其他回答

如果你想“撤销”所有未提交的更改或本地更改,只需运行:

git add . 
git stash 
git stash drop
git clean -fdx

Git中有三个选项可以帮助撤消本地更改。

要查看在你的工作目录中所做的更改,你应该运行git status:

git status

用git stash撤销更改 要丢弃所有本地更改,但也要保存它们以供以后使用,您可以运行git stash命令:

git stash

用git签出撤消更改 要永久丢弃对文件的本地更改,您可以运行:

git checkout -- <file>

用git重置撤销更改 要永久丢弃对所有文件的所有本地更改,您可以执行:

git reset --hard

来源:https://www.w3docs.com/snippets/git/how-to-discard-unstaged-changes.html

对于那些到达这里搜索是否可以撤消git clean -f -d的人,通过它在eclipse中创建的文件被删除,

你也可以在UI中使用“restore from local history”为ref: restore from local history进行同样的操作

# Navigate to project root, `.` works too.
git restore *

git状态显示我有一些文件被更改,但我想摆脱这些并开始一个新的分支。直到今天,我一直在使用git重置方法,我喜欢用它来跳回其他特定的提交。

https://www.git-tower.com/learn/git/commands/git-restore/

我要做的是

git add . (adding everything)
git stash 
git stash drop

一行代码:git add。少不更事的藏匿物,少不更事的藏匿物掉落

贾斯廷指出的一个更短的版本

Git stash -u && Git stash drop