Skip to contentSkip to conversation

Why does git stash create two commits?

DISCUSSION Phillip Susi 3 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

git stash makes two commits, one that has no changes from the base, and one to stash your changes in. Why?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPJt97AAoJEJrBOlT6nu75G1cH/1qXXMFBPr5vGZbPXCCgG4eG nmTVlVjxa9Wk52rY/o3NfrgDrftuKIeMdjrFxe/hOsuU37rfMUpWlGa6wtwOIgHL Cm2s/+PssrOwpajb+v3h+0vqZGNULaxPNpApDjB4JWTxNs86aCV/+zkzoqNjO8y4 OfAZnzqe03BJmPjldvygswD0RMvRvBuHyGRVhTgATcc89yZmihFxCNyekHdVUSvD zVIUgyUj1vlSRDnSJrtARbKR3JZQeTtN6rMLIOxN0T3iOkltMWFGMoVbJ23kiUyD LuMSNMrBvvkEU6g6czqQNNyreSut/b1r1ZTt/pvF0qDWUE5CZ9Qhgs6Xz7prtWs= =Yp0K
-----END PGP SIGNATURE-----

#1 lore raw

In message <[email protected]>, Phillip Susi writes:

git stash makes two commits, one that has no changes from the base, and one to stash your changes in. Why?

git-stash can make up to three commits:

working directory (of files git knows about) index
working directory (of files git does not know about)

The third commit only appears if you use --all or --include-untracked.

Most likely you do not use -u/-a and your index has not been touched yet, so you only see two commits, of which one is empty.

-Seth Robertson

#2 lore raw
In reply to Phillip Susi
Quoted 2 lines · Phillip Susi

git stash makes two commits, one that has no changes from the base, and one to stash your changes in. Why?

The only reason the former is identical to the base is because you are not incrementally building your next commit using "git add". It represents the state of your index. The latter represents the state of the tracked files in your working tree.