Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-stash

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.

like image 249
Chance Avatar asked Apr 14 '15 19:04

Chance


People also ask

Can you git stash individual files?

The git stash command stashes all tracked files in the current working directory. Stashing a specific file requires the additional push option along with the file name. For example: Running the command stashes only the specified readme.md file, while any other files that may have been changed remain unstashed.

How do I stash just some files?

To stash a specific file, use the “git stash push” command and specify the file you want to stash. However, the other tracked files that may be modified in your current working directory are untouched.

How do I stash files in git GUI?

To stash uncommitted local changes in Git using the terminal, you will simply run the Git stash command. This will put your working copy in a clean state and allow you to run different commands, such as Git checkout or Git pull.

How do you Unstash a specific stash?

To pop a specific stash in git, you can use the git stash apply command followed by the stash@{NUMBER} command. command. It will show the list of stashes you have saved.


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.

like image 79
Brett Zamir Avatar answered Oct 01 '22 04:10

Brett Zamir


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 the HEAD 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.


1git 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 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.

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).

like image 36
axiac Avatar answered Oct 01 '22 02:10

axiac


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

It might solve your problem.

like image 33
Anshul Mengi Avatar answered Oct 01 '22 03:10

Anshul Mengi