The use-case scenario is as follows:
git checkout branch-1
[introduce some changes I don't want to commit (but want to preserve)]
git stash save "my useful changes"
git checkout branch-2
[do some business with branch-2]
git checkout branch-1
git stash apply # the last stash which is "my useful changes"
Now, say I want to go back to branch-2
again. I am almost sure didn't introduce any new changes, so I don't want to create another stash if the changes are the same. I want to still have my stash with the same stash message.
I can manually check if the changes are the same (compare the diffs). And then either git reset / git stash; git stash drop
in case they are indeed the same or create a new stash if they are not.
Is there a way to to this more automatically?
Solutions which are not good enough:
- If I simply do
git stash
again, it creates a new stash (even if the contents and the message are identical to those of the top stash). - If I use
git stash pop
each time after I return tobranch-1
, I'll loose the stash message and so I'll have to re-type it each time. - If I do hard reset, I have to first check to make sure I didn't introduce any new changes other that changes in my top stash (so it's not automatic).
You could always say "write a script and it'll be automatic" and it's true. I want to know is there a feature integrated in git. So I consider a simple well-founded "No" a good answer.