是否有图形方式 git stash/unstash 单个文件?

Is there a graphical way to git stash/unstash individual files?

我正在寻找用于在 git 中存储和存储弹出文件的 GUI,并且能够对单个修改后的文件执行此操作。我知道有一种命令行方式可以做到这一点,见 here,但我正在寻找一种图形方式。我不太关心存储单个文件,但更关心popping/applying。我 运行 Windows 7.

你试过Sourcetree吗: http://www.sourcetreeapp.com/

它可能会解决您的问题。

git stash 的文档说:

Use 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. The command saves your local modifications away and reverts the working directory to match the HEAD commit.

它提供很少的支持1 来处理单个文件,因为它的目的是安全地存储您当前的更改并快速将您的工作树恢复到干净状态(即,像以前一样在当前分支上最后一次提交后立即执行。

如果您创建一个新分支并在其上提交更改(以您想要的任何数量或组合)直到达到您想要的状态,您就可以做您想做的事(并且比存储更灵活)。然后只需检查上一个分支就可以了。

这种方法允许您稍后将更改合并到当前分支,以便仅从中挑选一些提交甚至一些文件。


1 git stash save 提供选项 --patch 允许用户从 HEAD 和工作树之间的差异中交互式地选择帅哥被藏起来。它允许对添加到存储中的内容进行精细控制。

额外讨论

你说:

I'm using git coming from Perforce, so I'm trying to make stash fit in the 'shelve' mold, but I think branching is the better way to do it. Tied to this is that gitextensions sort of makes a branch out of my stashes, so I may be able to stash but treat it like a branch when grabbing individual files.

在内部,每个存储都 stored as a commit 链接到创建存储时 HEAD 的提交,但不链接到以前的存储(如果有)。存储列表存储为元数据;藏品 未链接 在(隐藏)分支中。

此外,git stash create 允许创建存储而不将其添加到存储列表中。它是为脚本和 "probably not the command you want to use" 提供的(我从文档中引用)。

我看到有人建议 here 将 Stash 命令作为菜单添加到 <USER HOME directory>\.gitconfig 中的 "Git GUI"。

[guitool "Stash/show"]
  cmd = git stash show -p
[guitool "Stash/list"]
  cmd = git stash list
[guitool "Stash/pop"]
  cmd = git stash pop
[guitool "Stash/drop"]
  cmd = git stash drop
  confirm = yes

我还添加了一个命令来执行隐藏(要使用,您必须首先阶段——但不是提交——您希望隐藏的文件,以便 Git 执行所需的 "add"):

[guitool "Stash"]
  cmd = git stash

(请注意,我选择让 "stash" 不显示为子菜单,但您可以这样做。)

您还可以通过 Git GUI 本身通过工具->添加添加命令。

如果您只是想快速将文件放在心上而不用费心去想分支名称,那么存储会很有帮助。