From: Junio C Hamano <gitster@pobox.com>
To: Shaun Cutts <shaun@cuttshome.net>
Cc: git@vger.kernel.org
Subject: Re: git index: how does it work?
Date: Wed, 05 Aug 2009 11:00:27 -0700 [thread overview]
Message-ID: <7v7hxi9m4k.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <loom.20090805T160528-69@post.gmane.org> (Shaun Cutts's message of "Wed\, 5 Aug 2009 16\:21\:38 +0000 \(UTC\)")
Shaun Cutts <shaun@cuttshome.net> writes:
> I am wondering if someone could explain and/or point me to an explanation of how
> the git index works.
>
> For instance, suppose I have a tracked file: "foo.c"
>
> 1) [I modify "foo.c"]
> 2) git add foo.c
> 3) [modify again]
> 4) git commit -m "blah blah"
>
> Since I don't include the "-a" switch, the version I added on step 2 is
> committed. But how does the index keep track of these changes? Does the index
> file actually contain the hunks of "foo.c" that have been modified? Or is there
> a "temporary" blob created, which the index points to?
Step 2 hashes foo.c and creates a blob object and registers it to the
index. Step 4 writes out the index as a tree and makes a commit out of
it.
Running this sequence might be instructive.
1$ edit foo.c
2$ git add foo.c
2a$ git ls-files -s foo.c
2b$ git diff foo.c
2c$ git diff --cached foo.c
3$ edit foo.c
3a$ git ls-files -s foo.c
3b$ git diff foo.c
3c$ git diff --cached foo.c
4$ git commit -m 'half-edit of foo.c'
4a$ git ls-files -s foo.c
4b$ git ls-tree HEAD foo.c
4c$ git diff foo.c
4d$ git diff --cached foo.c
- 2a shows the actual blob object that was created out of foo.c in step 2.
- 2b shows the difference between that blob (now in the index) and foo.c,
which should be empty.
- 2c shows the difference between the HEAD commit and the index, which
should show your edit in step 1.
- 3a shows the blob in the index; you haven't added, so it should show
the same as 2a.
- 3b shows the difference between the index and foo.c, which should show
the edit in step 3.
- 3c shows the difference between the HEAD commit and the index, which
should show your edit in step 1.
- 4a shows the blob in the index; you haven't added, so it should show
the same as 2a.
- 4b shows the blob in the committed tree and the blob object should be
identical to 2a.
- 4c shows the difference between the index and foo.c, which should show
the edit in step 3.
- 4d shows the difference between the HEAD commit and the index, which
should now be empty.
next prev parent reply other threads:[~2009-08-05 18:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-05 16:21 git index: how does it work? Shaun Cutts
2009-08-05 18:00 ` Junio C Hamano [this message]
2009-08-12 11:52 ` Shaun Cutts
2009-08-12 17:47 ` Sverre Rabbelier
2009-08-12 18:45 ` Shaun Cutts
2009-08-12 19:39 ` Björn Steinbrink
2009-08-12 20:31 ` Junio C Hamano
2009-08-05 18:21 ` Sverre Rabbelier
2009-08-05 19:31 ` Shaun Cutts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v7hxi9m4k.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=shaun@cuttshome.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox