且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何撤消“放弃所有更改”在VS Code / Git中

更新时间:2022-11-16 08:34:21

因为VS代码中的全部清除基本上执行

  git clean -fd 
git checkout - 。

因此,如果 git clean -fd 可以取消放弃未提交的更改。



不幸的是,这些更改并没有存储在git中,因为它没有提交,所以执行这个命令后,git会清理未跟踪的文件在执行命令 git checkout - 。之后,git将签出git中的所有修改过的文件。

作为上次提交的版本。

I fear I already know the answer but here goes anyway.. I accidentally clicked "Discard All Changes" in VS Code (OSX) and now a month's worth of work is gone. Poof'd. Thing is, I didn't have GIT properly setup so I hadn't done any commits yet. Is there anyway I can get my work back? Right now my working directory is as good as empty..

[edit] I should clarify, the console log says it did a "git clean -f -q" which would mean the files are gone. But I was wondering if VSCode maybe has a backup or history or cache.. or anything. I'm desperate..

Since Clean All (discard all changes) option in VS code essentially execute

git clean -fd
git checkout -- .

So it’s the business for git that if git clean -fd can undo discarding uncommitted changes.

Unfortunately the changes are not stored in git since it not committed, so after this command executed, git will clean untracked files by force.

After after execute the command git checkout -- ., git will checkout all the modified files in git as the version of last commit.