IntelliJ 的 Shelve 和 Git stash 有什么区别?

What is the difference between IntelliJ's Shelve and Git stash?

IntelliJ 支持 git 存储以及它自己内置的搁置命令。这些似乎在目的和效用上几乎相同。它们有什么区别?

来自 IntelliJ documentation:

In the Git integration, in addition to shelving and unshelving, "stashing" and "unstashing" are supported respectively. These features have much in common, the only difference is in the way patches are generated and applied.

  • Patches with stashed changes are generated by Git itself. To apply them later, you do not need IntelliJ IDEA.
  • Patches with shelved changes are generated by IntelliJ IDEA. Normally, they are also applied through the IDE. Applying shelved changes outside IntelliJ IDEA is also possible but requires additional steps.

它们非常相似,除了:

  • 你不能在 IDE 之外使用 shelve,因为它是 Intellij 的特性。
  • Git stash 仅适用于整个工作目录和索引。 IntelliJ 的搁置可以处理单个文件和更改列表(另一个 IntelliJ 功能)。如您所见,例如here,有时是必要的。
  • Idea 内置了更好的搁置支持。使用 git 存储更直接。特别是,您可以 shelve\unshelve 您的更改或通过版本控制工具 window 查看搁置的文件 window。

此外,恕我直言,搁置的速度稍快一些,尤其是在大型项目中,当更改了大量文件时。

有关详细信息,请参阅 documentation

Intellij 的 Shelve 相对于普通 Git 的存储的一个明显优势是使用 Shelve,您可以将属于多个存储库的更改保存在一个更改列表中。使用 stash,你需要在每个 repo 中单独 stash/unstash。这在具有多个模块(每个模块都有自己的存储库)的大型项目中非常有用,其中特定功能工作可能跨越多个模块(因此多个存储库)

这是Documentation说的

Stashing changes is very similar to shelving. The only difference is in the way patches are generated and applied. Stashes are generated by Git, and can be applied from within IntelliJ IDEA, or outside it. Patches with shelved changes are generated by IntelliJ IDEA and are also applied through the IDE. Also, stashing involves all uncommitted changes, while when you put changes to a shelf, you can select some of the local changes instead of shelving them all.