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
32
votes
1 answer

List modified file names in a git stash

Can I list the names of the modified files in a stash, without their contents? While searching, I only found people printing the whole diff, couldn't manage to view the filenames only.
o0'.
  • 11,739
  • 19
  • 60
  • 87
31
votes
4 answers

Resolving Git merge conflicts

A Git repository has been cloned on several developers' local machines. Some changes have been made to the code in the repository. We're now getting the error: error: Your local changes to the following files would be overwritten by merge: …
g_thom
  • 2,810
  • 2
  • 18
  • 18
31
votes
2 answers

how to get the stash back after pulling

Yesterday I made some changes on the master branch but didn't commit them, today I tried to pull the master but it said I have to commit or stash my changes Please, commit your changes or stash them before you can merge. I stashed them git stash…
farm command
  • 653
  • 3
  • 7
  • 18
30
votes
2 answers

git diff for a single file in stash

I know from this answer how to show the diff against a stash. git stash show -p stash@{1} But how can I show the diff to a specific file from a stash?
Black
  • 18,150
  • 39
  • 158
  • 271
29
votes
4 answers

Undo IntelliJ Smart Checkout

IntelliJ has a feature that's very cool in theory, called Smart Checkout. This feature kicks in when you're changing branches and you have files in the current branch that you've modified but haven't committed. Instead of forcing you to commit,…
mlissner
  • 17,359
  • 18
  • 106
  • 169
29
votes
3 answers

git stash reporting: '' is not a stash reference

Not quite sure what's happened, but git stash seems to be in a bad place. % git stash list stash@{0}: filter-branch: rewrite stash@{1}: filter-branch: rewrite stash@{2}: On mysolr: start mysolr stuff Is OK, and git show stash@{0} works fine. …
Hamish Downer
  • 16,603
  • 16
  • 90
  • 84
28
votes
3 answers

Where are Git Stashes stored?

I have been using PhpStorm and recently stashed a load of my changes. At some point after that, my PC profile became corrupt and had to be rebuilt. Now that I have a new PC profile, PhpStorm is not showing my stashed changes. Is there any way I can…
Typhoon101
  • 2,063
  • 8
  • 32
  • 49
28
votes
4 answers

How do I properly git stash/pop in pre-commit hooks to get a clean working tree for tests?

I'm trying to do a pre-commit hook with a bare run of unit tests and I want to make sure my working directory is clean. Compiling takes a long time so I want to take advantage of reusing compiled binaries whenever possible. My script follows…
Hounshell
  • 5,321
  • 4
  • 34
  • 51
27
votes
5 answers

Apply stash to different branch

I was accidentally working on the wrong branch. Now I want to transfer all my changes to the correct branch. If I stash the changes and apply them on the correct branch, will it only add the uncommitted changes to the correct branch or every…
MeesterPatat
  • 2,671
  • 9
  • 31
  • 54
27
votes
1 answer

Why is a stash represented as 2 commits?

When stashing some changes, Git creates two separate commits, 'WIP on branch' and 'index on branch': $ git log --graph --all * commit 98aac13303ca086580c1ec9ccba5fe26c2a8ef3c |\ Merge: 7d99786 82c5c76 | | Author: Tieme | | Date: …
Tieme
  • 62,602
  • 20
  • 102
  • 156
27
votes
4 answers

Use git stash save or git commit for local changes?

I changed some files in my repo, but don't want them to be pushed public or create any temporary branch to store them. I just want to save these changes in somewhere. So which command is better: git stash save "save message" or git commit -am…
Balthier
  • 382
  • 1
  • 4
  • 8
26
votes
6 answers

git: Automatically stash+pop on checkout

If I do git checkout my-super-branch git tells me: error: Your local changes to the following files would be overwritten by checkout: somedir/somefile.py Please, commit your changes or stash them before you can switch branches. Aborting Is…
guettli
  • 25,042
  • 81
  • 346
  • 663
26
votes
2 answers

How many / how long are stashes saved by git?

I'm very new to git and have some question about stashing. If I've worked on a branch but was not able to get to a position where I can commit the branch, stashing is the right thing to use. My questions regarding stashing are: How many stashes are…
math
  • 1,868
  • 4
  • 26
  • 60
25
votes
3 answers

Delete all Git Commit History

I am trying to fetch a repo from Github, revert a tag in past, push it to another remote with deleting all history. I can do everything with below except deleting all commit logs. What I am missing? git clone https://github.com/user/user-repo.git cd…
noway
  • 2,585
  • 7
  • 41
  • 61
24
votes
5 answers

How to remove range of git stash?

I want to remove all stash'es, except most recent, from git stash list. E.g. I want to remove stash 1 to 3 in a single git command: stash@{0}: On master: Test related changes stash@{1}: On master: Tets stash@{2}: On master: Integrate bunyan…
Aditya Singh
  • 15,810
  • 15
  • 45
  • 67