英文:
What's the difference between "Discard all changes" and "Stash all changes"?
问题
我想撤销命令 npm create vite@latest
。我想恢复我的更改,而不让它们显示在 git 记录中或保存它们。
在 Visual Studio Code 的 源代码控制 选项卡上,当你悬停在未暂存更改上方时,会出现两个按钮:
悬停在一个按钮上时,会显示:
另一个按钮上则显示:
它们之间有什么区别?
如何在 Git 命令行中复制它们的行为?
英文:
I want to undo the command npm create vite@latest
. I want to revert my changes without them showing up in git log or them being saved.
In Visual Studio Code's Source Control tab there are two buttons on top of unstaged changes, which appear when you hover over them:
On hover one says:
And the other reads:
What is the difference between them?
How can I replicate their behavior with the Git CLI?
答案1
得分: 6
-
如果您选择"丢弃",您的更改将被删除,恢复它们将变得更加困难(请参阅 https://stackoverflow.com/questions/43541167/how-do-you-undo-discard-all-changes-in-vs-code-git)。
相应的Git命令类似于
git restore <file>
或
git checkout -- <file>
例如,您可以使用
git restore .
或git checkout -- .
来丢弃所有更改。(有几个可能具有类似效果的命令;请参阅 https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state)
-
如果您选择"存储",您的更改将被临时移除,但您稍后可以恢复它们(请参阅例如 https://stackoverflow.com/questions/20537223/what-is-the-intended-use-case-for-git-stash 或 https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning)。
相应的Git命令是
git stash
英文:
-
If you choose "Discard", your changes are gone and there will be no simple way of recovering them (see https://stackoverflow.com/questions/43541167/how-do-you-undo-discard-all-changes-in-vs-code-git).
The corresponding Git command is something like
git restore <file>
or
git checkout -- <file>
e.g., you can use
git restore .
orgit checkout -- .
to discard everything.(There are several possible commands which have similar effects; see https://stackoverflow.com/questions/1146973/how-do-i-revert-all-local-changes-in-git-managed-project-to-previous-state)
-
If you choose "Stash", your changes will temporarily be removed, but you will be able to recover them later (see e.g. https://stackoverflow.com/questions/20537223/what-is-the-intended-use-case-for-git-stash or https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning).
The corresponding Git command is
git stash
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论