Git 搁置与存储

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28008139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:48:47  来源:igfitidea点击:

Git Shelve vs Stash

gitintellij-ideajetbrains-ide

提问by Edgar Martinez

I am very unfamiliar with the shelveaspect of Git. If stashis used to put aside unfinished work what is shelvethen? What would you use it for?

shelve对 Git的方面非常陌生。如果stash是用来搁置未完成的工作那是shelve什么?你会用它做什么?

For example on Update Project (from VCS menu)

例如在更新项目(从 VCS 菜单)

enter image description here

在此处输入图片说明

one will get (in Idea 2019.2)

一个会得到(在 Idea 2019.2 中)

enter image description here

在此处输入图片说明

采纳答案by VonC

git shelvedoesn't exist in Git.

git shelveGit 中不存在。

Only git stash:

git stash

  • when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.
  • which saves your local modifications away and reverts the working directory to match the HEAD commit.
  • 当你想记录工作目录和索引的当前状态,但又想回到一个干净的工作目录时。
  • 这会保存您的本地修改并恢复工作目录以匹配 HEAD 提交。

You had a 2008 old project git shelveto isolate modifications in a branch, but that wouldn't be very useful nowadays.

你有一个 2008 年的旧项目git shelve来隔离分支中的修改,但现在这不是很有用。

As documented in Intellij IDEA shelve dialog, the feature "shelving and unshelving" is not linked to a VCS (Version Control System tool) but to the IDE itself, to temporarily storing pending changes you have not committed yet in changelist.

Intellij IDEA 搁置对话框中所述,“搁置和取消搁置”功能不链接到 VCS(版本控制系统工具),而是链接到 IDE 本身,用于临时存储您尚未在更改列表中提交的待处理更改。

Note that since Git 2.13 (Q2 2017), you now can stash individual files too.

请注意,自 Git 2.13(2017 年第二季度)以来,您现在也可以存储单个文件

回答by Yekver

When using JetBrains IDE's with Git, "stashing and unstashing actions are supported in addition to shelving and unshelving. These features have much in common; the major difference is in the way patches are generated and applied. Shelve can operate with either individual files or bunch of files, while Stash can only operate with a whole bunch of changed files at once. Here are some more detailson the differences between them."

将 JetBrains IDE 与 Git 一起使用时,“除了搁置和取消搁置之外,还支持存储和取消存储操作。这些功能有很多共同点;主要区别在于生成和应用补丁的方式。搁置可以处理单个文件或一堆文件文件,而 Stash 一次只能处理一大堆已更改的文件。这里有更多关于它们之间差异的详细信息。”

回答by valex

In addition to previous answers there is one important for me note:

除了之前的答案之外,还有一个对我来说很重要的注意事项:

shelveis JetBrains products feature (such as WebStorm, PhpStorm, PyCharm, etc.). It puts shelved files into .idea/shelfdirectory.

shelve是JetBrains的产品特征(如WebStormPhpStormPyCharm等等)。它将搁置的文件放入.idea/shelf目录。

stashis one of gitoptions. It puts stashed files under the .gitdirectory.

stashgit选项之一。它将隐藏的文件放在.git目录下。

回答by Hamza Belmellouki

I would prefer to shelve changes instead of stashing them if I am not sharing my changes elsewhere.

如果我不在其他地方分享我的更改,我宁愿搁置更改而不是隐藏它们。

Stashing is a git feature and doesn't give you the option to select specific files or changes inside a file. Shelving can do that but this is an IDE-specific feature, not a git feature:

Stashing 是 git 的一项功能,不提供选择特定文件或文件内更改的选项。Shelving 可以做到这一点,但这是 IDE 特定的功能,而不是 git 功能:

enter image description here

在此处输入图片说明

As you can see I am able to choose to specify which files/lines to include on my shelve. Note that I can't do that with stashing.

如您所见,我可以选择指定要包含在我的书架上的文件/行。请注意,我不能通过隐藏来做到这一点。

Beware using shelves in the IDE may limit the portability of your patches because those changes are not stored in a .git folder.

请注意在 IDE 中使用架子可能会限制补丁的可移植性,因为这些更改未存储在 .git 文件夹中。

Some helpful links:

一些有用的链接: