threads / discuss / 29483

Why does git stash create two commits?

Subject: Why does git stash create two commits?

## tl;dr

3 messages between Jan 30, 2012 and Jan 30, 2012.

replies: 2people: 3as markdown or json

Phillip Susi· Jan 30, 2012, 18:20 UTC · lore
-----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-----

Seth Robertson· Jan 30, 2012, 18:25 UTC · re: Phillip Susi · lore

Re: Why does git stash create two commits?

In message <4F26DF7B.7050109@ubuntu.com>, 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
Junio C Hamano· Jan 30, 2012, 19:11 UTC · re: Phillip Susi · lore

Re: Why does git stash create two commits?

Phillip Susi <psusi@ubuntu.com> writes:
> 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.

← back to recent threads