From: Junio C Hamano <gitster@pobox.com>
To: "Neal Kreitzinger" <neal@rsss.com>
Cc: git@vger.kernel.org
Subject: Re: Can I checkout a single file without altering index?
Date: Fri, 15 Oct 2010 16:22:59 -0700 [thread overview]
Message-ID: <7viq13avn0.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <i9a6kn$d7o$1@dough.gmane.org> (Neal Kreitzinger's message of "Fri\, 15 Oct 2010 13\:30\:06 -0500")
"Neal Kreitzinger" <neal@rsss.com> writes:
> FWIW, my understanding of the index is that it is the middle-man for moving
> things from your work-tree to the object-store AND for moving things from
> the object-store to your work-tree.
While there is nothing technically incorrect in the above, it probably
is easier to explain/understand why it works in the direction from the
object store and to the working tree if you state it this way instead:
The index is where you build the contents for your next commit.
- You build your next commit starting from the current commit,
so when you do "checkout" from the object store, both the
index and the working tree are populated with the blob.
- You then modify that state in your working tree, hopefully
testing, reviewing, and thinking about your change while
doing so.
- There may be good changes, not good enough changes, and
perhaps only for debugging changes in your working tree. You
can decide to make commits out of only the good bits, leaving
others uncommitted. You add only good bits to your next
commit, and the command to do so is naturally called "git
add" (and "git add -p" for add changes to a file partially by
picking patch hunks).
- There may be a time where you regret that some changes you
made to your working tree are not good, and want to start
over. You may even do so after you added some changes to
the index (i.e. your next commit). By checking the path
out of the current commit would give you the original
version of the path both in the index and in the working
tree file to help you start over.
- After making that commit, you will keep working to create
the commit next to that commit you created. To help you
work incrementally, the index at that point contains what
you committed.
> However, there is an option in git-commit to copy files directly from the
> working-tree to the object-store by totally bypassing the index, but no one
> seems to do this or recommend doing this as normative practice.
This is wrong. People do this all the time with "git commit $path".
What happens behind the scene is:
- git prepares a temporary index that matches the contents of the
current commit;
- the contents for $path from the working tree is then added to that
temporary index;
- a new commit is written out of that temporary index; and
- the $path is also added to the real index (this is a very important
detail---otherwise the next commit will lose the change to $path).
Notice that in no step the index is really bypassed. Everything
literally goes through the index.
If you want to bypass the index, you can do so with cat-file or show; it
just is not a useful operation in a normal workflow of building the next
commit on top of the current one, and that is the only reason why there
is no option such as "checkout --no-index HEAD~47 path". If somebody
can write a convincing use case that shows why it is useful, such an
option shouldn't be very hard to add. But I don't think of any. For
example, this is not it:
I start from a clean slate and start working.
$ git checkout
$ edit; git diff; compile; test; git add path ;# repeat
At this point I have some cooked contents added for the next commit
in the index for path. But I realize that the contents of that path
in another branch might be even better. But I do not want to lose
the state I arrived at, which might be better than that alternative.
I cannot decide, so I'll keep that in the index for now.
$ git checkout --no-index the-other-branch path
$ edit; compile; test; ...
case I. yes the other one indeed is better
$ git add path
case II. no the other one is inferiour
$ git checkout path ;# out of index
While superficially this looks promising, this is unwieldy. For one
thing, you cannot easily check what you changed anymore, as "git diff
path" would show the difference between the index, i.e. a version that
was modified in a different way from the current version, and the
working tree, i.e. another version that was modified starting from a
totally different version in the-other-branch.
next prev parent reply other threads:[~2010-10-15 23:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-12 10:03 Can I checkout a single file without altering index? Christian Halstrick
2010-10-12 10:19 ` Michael J Gruber
2010-10-12 11:14 ` Stefan Naewe
2010-10-13 17:09 ` Jared Hance
2010-10-12 15:39 ` Alex Riesen
2010-10-12 16:39 ` Tomas Carnecky
2010-10-14 8:03 ` Christian Halstrick
2010-10-15 18:30 ` Neal Kreitzinger
2010-10-15 18:43 ` Jonathan Nieder
2010-10-15 18:55 ` Jeff King
2010-10-15 19:32 ` Jonathan Nieder
2010-10-15 19:48 ` Jeff King
2010-10-15 18:57 ` Neal Kreitzinger
2010-10-15 19:02 ` Andreas Schwab
2010-10-15 23:22 ` Junio C Hamano [this message]
2010-10-15 23:40 ` Jonathan Nieder
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7viq13avn0.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=neal@rsss.com \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).