How do I get access to data git stash refuses to merge
I ran
git stash # two files not stashed since they were not in git yet
git stash -u # add the sfiles to the stash
git pull
git stash pop
Git refuses to un-stash because the pull has two files that were added with (-u untracked files)
error: could not restore untracked files from stash
The stash entry is kept in case you need it again.
git stash show 0
shows nothing. Is there a way to get at the files given stash wont pop? Is there a patch file in .git somewhere?
A stash is just a commit, so you can use regular tools like
git show
to access files in the stash. Let's say I have one unstaged change and one untracked file:If I run
git stash -u
, I end up with a commit object namedrefs/stash
:Unstaged changes (that is, changes to files that are tracked by git) are stored directly in
refs/stash
:I can extract an individual file like this:
Untracked files are stored in
refs/stash^3
:And I can extract files in a similar fashion:
We can also check out the stash as a new branch. Using
git worktree
allows us to put this in a new directory. The following creates a new branch namedunstaged-changes
with the contents ofrefs/stash^3
and checks it out into the../unstaged-changes
directory: