4

I've made changes in my working directory and then run git stash. In my .dir/refs directory I've got a new reference called stash, which is a pointer to the object with hash 2d05be16dcd0828c84d63f1e07ee78a2a28b3deb. I've checked the type of the object and it's commit:

$ git cat-file -t 2d05be16dcd0828c84d63f1e07ee78a2a28b3deb
commit

So it seems that stashing indeed creates a commit. So when I unstash it, is it equivalent to cherry-picking it?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • 1
    This may be of interest: http://stackoverflow.com/questions/26021591/why-wip-and-index-commit-listed-on-develop-after-stash/26022071#26022071 – jub0bs Jan 21 '15 at 10:12
  • 2
    This as well https://codingkilledthecat.wordpress.com/2012/04/27/git-stash-pop-considered-harmful/ – user2202911 Jan 21 '15 at 10:20
  • If I had to guess, I would say that git probably uses `git read-tree` to apply the changes of the stash commits. – Sascha Wolf Jan 21 '15 at 10:41

1 Answers1

0

Not exactly, but it's similar. Applying stashed changes modifies the index and/or the working tree, but never creates a new commit. After a succesful cherry-pick, the index and working tree will be exactly the same, and a new commit will have been created.

That said, the way changes are applied will be pretty much the same. Git needs some way to apply the changes from a specific commit to an arbitrary tree, and it makes no sense to use different implementations for git stash and git cherry-pick.