30

The Magit user manual includes two sets of "stashing" commands: lower-case commands save a stash, and upper-case commands save a snapshot. After consulting Google and Stack Overflow and the git-stash(1) man page, I still don't know what the difference is.

What's the difference?

1
  • 1
    My understanding is that stash will also reset (undo) the changes and snapshot will leave the changes in the workspace (could be useful if you are going to rearrange commits before pushing).
    – wvxvw
    May 23, 2016 at 14:46

1 Answer 1

36

Both the "stash" and "snapshot" variants create the same stash objects. The difference is that when you create a snapshot, then the stashed changes are not removed from the files in the working tree and/or the index. (Just like when you take a snapshot of your friends having a good time - that doesn't cause them to disappear either ;-)

This is intended as a backup mechanism of sorts. Say you are performing some complicated refactoring and you just tested and the modified code still appears to work but you are not done yet. Now would be a good time to create a snapshot, so that you have something to go back to if you mess it up later.

Of course you could just create a temporary "wip" commit, right on the branch you are working on, to accomplish the same. That's usually what I do.

And you can also automate the process of recording work-in-progress by enabling the Wip modes. I do have these modes enabled as a safety net, but I still create wip commits directly on the current branch or create a snapshot. Those are easier to work with than the wip refs.

Note that Magit comes with its own stash implementation written in Elisp. That was necessary to implement the snapshot variants and the worktree-only and index-only stash variants. Git doesn't provide any of these variants.

1
  • I guess the closest we can get to snapshotting with Git's own CLI is git stash && git stash apply to put away the changes and then immediately copy them back out?
    – mtraceur
    May 31 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.