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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29635601/
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-19 10:54:25  来源:igfitidea点击:

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

gitgit-stash

提问by Chance

I am looking for a GUI for stashing and stash popping files in git, with the ability to do so for individual modified files. I know there is a command line way to do so, seen here, but I am looking for a graphical way. I don't care so much about stashing individual files, but more about popping/applying. I am running on Windows 7.

我正在寻找一个用于在 git 中存储和存储弹出文件的 GUI,能够为单个修改的文件执行此操作。我知道有一种命令行方式可以这样做,见here,但我正在寻找一种图形方式。我不太关心隐藏单个文件,但更关心弹出/应用。我在 Windows 7 上运行。

采纳答案by axiac

The documentation of git stashsays:

的文档git stash说:

Use git stashwhen 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 HEADcommit.

使用git stash时要录制工作目录和索引的当前状态,但想回到干净的工作目录。该命令保存您的本地修改并恢复工作目录以匹配HEAD提交。

It provides very little support1to handle individual files because its purpose is to safely store your current changes and quickly bring your working tree to a clean state (i.e. as it was immediately after your last commit on the current branch).

它提供很少的支持1来处理单个文件,因为它的目的是安全地存储您当前的更改并快速使您的工作树进入干净的状态(即,就像您在当前分支上最后一次提交之后一样)。

You can do what you want (and in a more flexible way than stashing) if you create a new branch and commit the changes on it (in any amount or combination you want) until you reach the status you desire. Then just checkout the previous branch and you're done.

如果您创建一个新分支并提交对它的更改(以您想要的任何数量或组合),您可以做您想做的事情(并且以比 stashing 更灵活的方式),直到达到您想要的状态。然后只需签出上一个分支即可完成。

This approach allows you to merge the changes into the current branch later, to cherry-pick only some commits or even some files from them.

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



1git stash saveprovides the option --patchthat allows the user to interactively selects hunks from the diff between HEADand the working tree to be stashed. It allows fine control over what is added to the stash.

1git stash save提供了--patch允许用户从HEAD要隐藏的工作树之间的差异中交互选择大块的选项。它允许对添加到存储中的内容进行精细控制。

Extra discussion

额外讨论

You say:

你说:

I'm using gitcoming 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 gitextensionssort 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.

我正在使用git来自 from Perforce,所以我试图让 stash 适合“搁置”模具,但我认为分支是更好的方法。与此相关的是gitextensions那种从我的藏匿处创建一个分支,所以我可能能够藏匿但在抓取单个文件时将其视为一个分支。

Internally, each stash is stored as a commitlinked to the commit that was the HEADat the moment when the stash was created, but not linked to the previous stash (if any). The list of stashes is stored as meta-data; the stashes are not linkedin a (hidden) branch.

在内部,每个 stash 都存储为一个提交,链接到HEAD创建 stash 时的提交,但不链接到前一个 stash(如果有)。存储列表存储为元数据;该窝点都没有联系的(隐藏)分支。

More, git stash createallows the creation of a stash without adding it into the list of stashes. It is provided for scripting and "probably not the command you want to use"(I quoted from the documentation).

更多,git stash create允许在不将其添加到存储列表中的情况下创建存储。它是为编写脚本而提供的,并且“可能不是您要使用的命令”(我从文档中引用)。

回答by Brett Zamir

I saw a recommendation hereto add the Stash commands as a menu to "Git GUI" in your <USER HOME directory>\.gitconfig.

我在这里看到了一个建议,将 Stash 命令作为菜单添加到 .git 文件中的“Git GUI” <USER HOME directory>\.gitconfig

[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

I also added one more command to do the stashing (to use, you must first stage--but not commit--the files you wish stashed in order for Git to perform the required "add"):

我还添加了另一个命令来进行存储(要使用,您必须首先暂存 - 但不要提交 - 您希望存储的文件,以便 Git 执行所需的“添加”):

[guitool "Stash"]
  cmd = git stash

(Note that I chose to have "stash" not appear as a submenu, but you could do so.)

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

You can also add commands through Git GUI itself via Tools->Add.

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

Stashing can be helpful if you just want to put the files out of mind quickly without bothering to think of a branch name.

如果您只想快速忘记文件而不想考虑分支名称,那么存储可能会有所帮助。

回答by Anshul Mengi

Did you try Sourcetree: http://www.sourcetreeapp.com/

您是否尝试过 Sourcetree:http: //www.sourcetreeapp.com/

It might solve your problem.

它可能会解决您的问题。