How would I extract a single file (or changes to a file) from a git stash?

前端 未结 9 1492
一生所求
一生所求 2020-11-28 00:14

I\'d like to know if it is possible to extract a single file or diff of a file from a git stash without popping the stash changeset off.

Might anyone be able to prov

相关标签:
9条回答
  • 2020-11-28 00:42

    If you use git stash apply rather than git stash pop, it will apply the stash to your working tree but still keep the stash.

    With this done, you can add/commit the file that you want and then reset the remaining changes.

    0 讨论(0)
  • 2020-11-28 00:42

    The simplest concept to understand, although maybe not the best, is you have three files changed and you want to stash one file.

    If you do git stash to stash them all, git stash apply to bring them back again and then git checkout f.c on the file in question to effectively reset it.

    When you want to unstash that file run do a git reset --hard and then run git stash apply again, taking advantage ofthe fact that git stash apply doesn't clear the diff from the stash stack.

    0 讨论(0)
  • 2020-11-28 00:45

    You can get the diff for a stash with "git show stash@{0}" (or whatever the number of the stash is; see "git stash list"). It's easy to extract the section of the diff for a single file.

    0 讨论(0)
提交回复
热议问题