Questions tagged [git-stash]

Allows to move pending changes in a working git directory away and restore them later, i.e. put them on a stash. You can have multiple stashes and it can also be used to move pending changes to another branch.

git stash allows you to stash changes in working directory, and then restoring them later, possibly on another branch.

Stashing changes is usually necessary when you need a clean working copy, e.g. before using or .

Popular questions

See also

References

$ git stash --help
675 questions
141
votes
12 answers

Git stash: "Cannot apply to a dirty working tree, please stage your changes"

I am trying to apply changes I stashed earlier with git stash pop and get the message: Cannot apply to a dirty working tree, please stage your changes Any suggestion on how to deal with that?
avernet
  • 30,895
  • 44
  • 126
  • 163
127
votes
3 answers

git stash and git pull

I am new to Git and I am using EGit eclipse plugin to commit. I modified few files and I stashed the changes, then I did git pull in command line which pulled up all the latest commits. Then I did Apply stashed changes from EGit. Now it applied my…
Lolly
  • 34,250
  • 42
  • 115
  • 150
113
votes
13 answers

Why can't stash be applied to the working directory?

I cannot apply stash back to the working directory. Little story: First I tried to push some committed changes, but it said: "no you can't, pull first"... OK then, I'll pull things from GitHub and then push my changes. When I tried to pull, it said…
Miguel Angelo
  • 23,796
  • 16
  • 59
  • 82
105
votes
4 answers

How to stash changes in current folder?

I would like to stash only the changes in the current folder and its subfolders. How can I achieve that? I have tried the obvious approach - git stash . but it doesn't seem to work. I know I can create temporary commits and delete them afterward,…
stdcall
  • 27,613
  • 18
  • 81
  • 125
102
votes
3 answers

Git show all branches (but not stashes) in log

I have a Git alias that expands to: git log --graph --oneline --all --decorate According to man git log there are a couple of suspicious options: --not and --branches; but I can't make it work properly. How should I edit that to hide the…
cYrus
  • 2,976
  • 6
  • 29
  • 47
99
votes
3 answers

What's the difference between git stash save and git stash push?

When should I use git stash save instead of git stash push and vice-versa?
David Burson
  • 2,947
  • 7
  • 32
  • 55
99
votes
4 answers

Can't pop git stash, 'Your local changes to the following files would be overwritten by merge'

So I had a load of changes and some untracked files. I needed to tweak something, so I used git stash -u, modified a couple of things, committed those changes, pushed them, and then tried to git stash pop. Because I'd modified a couple of files that…
fredley
  • 32,953
  • 42
  • 145
  • 236
92
votes
5 answers

Change Git stash message

I have a stash saved for the future that I want to give a meaningful name. While it's possible to pass a message as argument to git stash save, is there a way to add a message to an existing stash?
CharlesB
  • 86,532
  • 28
  • 194
  • 218
88
votes
10 answers

Can git do a diff of the working copy with stash

How can I diff my current working copy against a stash? My use case: my working copy already contains a subset of the changes in my stash@{0}, but I don't want to apply all the changes in stash@{0}. I want to do a diff to help determine which…
Laughing monster
  • 889
  • 1
  • 6
  • 4
85
votes
5 answers

How to combine multiple stashes in git

This is a pipeline on branch frontend over the last two weeks. | Stash@{3} is all code since Stash@{1} (excluding the two tiny commits) | Tiny Commit | Tiny commit | Huge bulk commit two weeks ago, now rebased and moved to Stash@{1} My working tree…
sscirrus
  • 55,407
  • 41
  • 135
  • 228
85
votes
4 answers

Why isn't the git stash unique per branch?

I suppose it allows for moving changes from one branch to the next but that's what cherry picking is for and if you're not making a commit of your changes, perhaps you shouldn't be moving them around? I have on occasion applied the wrong stash at…
iros
  • 1,055
  • 1
  • 7
  • 8
79
votes
4 answers

Why does `git stash -p` sometimes fail?

I ♥ git stash -p. But sometimes, after a satisfying session of y, n, and s, I get this: Saved working directory and index state WIP on foo: 9794c1a lorum ipsum error: patch failed: spec/models/thing_spec.rb:65 error: spec/models/thing_spec.rb: patch…
John Bachir
  • 22,495
  • 29
  • 154
  • 227
76
votes
5 answers

Stash changes to specific files

I have a large git project that I, stupidly, imported to eclipse and ran an autoformat on. Now, every file in the project is showing as modified. Rather than commit my formatted files, I would rather revert all the files that I have only been…
ewok
  • 20,148
  • 51
  • 149
  • 254
75
votes
5 answers

Git command to save a stash without modifying working tree?

I have been wanting to use a git command that saves a stash without modifying my working tree, as a lightweight backup that's safe from any git resets or whatever I might do to screw up my index. Basically the functional equivalent of "git stash…
Eliot
  • 5,450
  • 3
  • 32
  • 30
72
votes
1 answer

Aborting `git stash apply`

I regret having applied a stash (wrong branch). How can I undo this and have my stash back to my stash list in order to apply it later on the right branch?
abernier
  • 27,030
  • 20
  • 83
  • 114