Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 4
    This is the only correct answer IMO. Using checkout or show will blindly overwrite your file instead of just applying changes. "One more way" is an understatement. Commented Dec 8, 2019 at 0:21
  • 3
    I'm not getting the path/to/file2 as the you want to diff against the same file in your workspace. Leaving out the second path works fine for me. - And I get an error message using the -R option ("apply the patch in reverse", trying to patch the stashed version?!). So my working version looks like git diff stash@{N}^! -- path/to/file | git apply - .
    – ThomasH
    Commented Jan 15, 2020 at 15:36
  • 2
    "patch failed"? Try a 3-way merge. ...| git apply -3 -
    – John Mee
    Commented Jan 23, 2020 at 22:41
  • diff stash@{N}^! already produces a forward diff, so omit -R
    – kxr
    Commented Aug 20, 2020 at 11:07
  • The ^! did not work in my case, so I ended up doing git diff stash@{N} -- path/to/file | git apply -R Commented Apr 16, 2021 at 15:34