How can I check an unused file in a git tag?

Suppose I have hidden some changes using one of:

git stash -u git stash --include-untracked 

I can check an individual file from the cache using

 git checkout stash@{0} -- filename 

This works if git knows about "filename", but does not work if "filename" is not tracked. Is there a way to check raw files from a wallet?

+8
git
source share
3 answers

git stash internally creates a special fusion of black magic to store various parts of your changes. A merge transaction has the original base commit (what you had at the top of the branch when you hid it) as its first parent, a one-time commit representing the contents of the index at the time of recording as the second parent, and (only if you used --include-untracked ) A one-time commit containing raw files as the third parent.

Thus, the merge merge refers to files that have not been verified (like one of his parents) ... but in fact he does not include these files in his own tree (if this makes no sense, or you have a few things to find out more about Git internals ... or you know too much about merging, and this whole construction seems too awful to think;)).

In short ... to access the unprotected parts of your wallet, contact its third parent: git checkout stash@{0}^3 -- filename

+16
source share

I have a branch from scratch, with which I experiment, but, as a rule, I do not undertake. I want to highlight a few individual changes in my real topic thread.

In this case, do not worry about changing the changes in order to move them from one branch to another. Make a git commit directly and push the changes from the branch that you moved to another using git cherry-pick : git cherry-pick #hash_of_the_commit .

+1
source share

For me, Jan Krüger's answer somehow didn't work (git 2.19.1). My workaround for checking individual files from cache:

Find the fixation of the identifier of the compilation part with unprepared files (the commit message has the prefix "unplayed files"):

 git log --name-status stash@{0} 

Then do the usual git checkout file in this commit:

 git checkout <commit id> -- <your file pathspec> 
0
source share

All Articles