6

I often use Atlassian'Sourcetree. It's really helpful GUI Git Client. But when I want to unstash specific files, Sourcetree'stash just apply all stashed changes. What I want to do is unstash selected files in SourceTree just like the following git command git checkout stash@{0} <filename>

Does anyone know how to do this?

Kazunori Takaishi
  • 2,268
  • 1
  • 15
  • 27
  • 1
    May we ask why you want to apply a partial stash in the first place? This a fairly atypical use of stash, I think. – Tim Biegeleisen May 15 '18 at 06:01
  • duplicate https://stackoverflow.com/a/8333163/9083959 short answer is, you can't – lukas-reineke May 15 '18 at 06:23
  • Possible duplicate of [Stash only one file out of multiple files that have changed with Git?](https://stackoverflow.com/questions/3040833/stash-only-one-file-out-of-multiple-files-that-have-changed-with-git) – lukas-reineke May 15 '18 at 06:24
  • It was a slightly misunderstanding expression, I think. In most cases, It's OK to unstash all changes. But sometimes I don't want all stashed changes applied. For example, In a project which many people develop together, I am working at brach A, and at some point I have to pull remote develop branch, to which we push or submit pull request. In this case, I stash local changes and then pull remote develop branch. Basically I accept changes at develop branch, but I want to apply some file's change of the stash. – Kazunori Takaishi May 15 '18 at 06:29
  • 1
    It may be partially duplicate, but I want to do the same thing **in SourceTree** as well as git command. – Kazunori Takaishi May 15 '18 at 06:39

1 Answers1

3

This is a fairly old question, but it popped up on my google search, so here's a partial answer.

To stash select files:

  1. Stage the files you want to stash.
  2. Then stash all files, but making sure that 'Keep staged changes' is checked.
  3. Now you only have the files you want to stash in your current working copy.
  4. Stash all files, with 'Keep staged changes' unchecked.
  5. You can then re-apply the first stash, and discard the files that you wanted to stash.

From here. Kind of awkward, but it is what it is.

I suppose what I would do is apply the whole stash without deleting it, use the above procedure to stash only the files you want to apply, discard everything, then apply the partial stash you built.

On the command line, you could probably short-cut a few steps, I suppose...

João Mendes
  • 1,719
  • 15
  • 32