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.
3 Answers
I saw a recommendation here to add the Stash commands as a menu to "Git GUI" in your <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"):
[guitool "Stash"]
cmd = git stash
(Note that I chose to have "stash" not appear as a submenu, but you could do so.)
You can also add commands through Git GUI itself via Tools->Add.
Stashing can be helpful if you just want to put the files out of mind quickly without bothering to think of a branch name.
-
Doesn't look too helpful, as all the command output is displayed in an extra popup window without all the niceties such as a colored diff.– nyiCommented Apr 22 at 11:37
The documentation of git stash
says:
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 theHEAD
commit.
It provides very little support1 to 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).
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.
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.
1 git stash save
provides the option --patch
that allows the user to interactively selects hunks from the diff between HEAD
and the working tree to be stashed. It allows fine control over what is added to the stash.
Extra discussion
You say:
I'm using
git
coming fromPerforce
, 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 thatgitextensions
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.
Internally, each stash is stored as a commit linked to the commit that was the HEAD
at 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 linked in a (hidden) branch.
More, git stash create
allows 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).
-
thanks. To clarify, I don't think the stash really is like a branch, but git extensions makes it appear so - which can be good or bad. git extensions provides a layer of abstractions, and sometimes it's not exactly clear what I'm doing.– ChanceCommented Apr 28, 2015 at 14:34
-
Indeed, gitextensions makes the list of stashes look like a branch; while this can help the beginners accommodate with
git
easier, it misleads them later. SourceTree presents the stashes as independent objects, the same way it shows the branches, the tags and the remotes. Give it a try (it's free), maybe you'll like it. It is also a Mercurial client.– axiacCommented Apr 28, 2015 at 14:51 -
"The list of stashes is stored as meta-data" - as far as I can see in the refs/logs/stash basically. What is
git save
you refer to ? Commented Jun 5, 2017 at 10:43 -
1@Mr_and_Mrs_D it should have been
git stash save
, I forgot thestash
when I wrote the answer. I fixed it now. Thank you for pointing it out.– axiacCommented Jun 5, 2017 at 11:07
Did you try Sourcetree: http://www.sourcetreeapp.com/
It might solve your problem.
-
3SourceTree is a good
Git
GUI client but it cannot stash individual files. Maybe this is because thestash
command was not designed to work this way?– axiacCommented Apr 15, 2015 at 8:33
git stash
was designed for a different thing (it is explained in the first paragraph of its documentation). 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 of combination you want) until you reach the status you desire. Then just checkout the previous branch and you're done.