16

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
    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 '16 at 14:46
23

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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