1

I am working on branch XYZ. I want to know how foo.c in this branch compares with stash{0} on master. Something like

git diff master@stash@{0} foo.c

which does not work. Now I want that stashes foo.c to replace my local file. Something like

git checkout master@stash@{0} foo.c

Edit: I did not realize that stashes aren't owned by a branch, but the stash itself identifies which branch it is a stash of. Problem solved.

eplictical
  • 583
  • 1
  • 6
  • 16
  • 1
    possible duplicate of [Git diff against a stash](http://stackoverflow.com/questions/7677736/git-diff-against-a-stash) – Roman Feb 12 '13 at 21:14
  • 1
    another possible duplicate [Git: how to diff the same file between two different commits on the same branch?](http://stackoverflow.com/questions/3338126/git-how-to-diff-the-same-file-between-two-different-commits-on-the-same-branch), although that talks about diffing on the same branch, it'll work across branches. – Roman Feb 12 '13 at 21:15
  • This is how you check out file from another commit (in your case stash): [How do I revert one file to the last commit in git?](http://stackoverflow.com/questions/692246/how-do-i-revert-one-file-to-the-last-commit-in-git) – Roman Feb 12 '13 at 21:17
  • @ROM those two duplicates you mention are diffing within the same branch right? I want to diff _between_ branches, and actually the stash of one branch. Isn't that different? – eplictical Feb 12 '13 at 21:49
  • 1
    @ROM ahhhh now I see why you say that. I just installed `gitg` which made it obvious to me that stashes are not subobjects of a branch but rather have an attribute indicating the branch they were stashed from! – eplictical Feb 12 '13 at 22:07
  • Yeah, at the end of the day they are all just commits with IDs. Git lets you compare any two commits, regardless of branch. You can also check out any mix of files from any branch into your working copy if you'd like. Whether that's an appropriate thing to do or not is up to you to decide. – Roman Feb 13 '13 at 00:06

0 Answers0