All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: Christian Halstrick <christian.halstrick@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Can I checkout a single file without altering index?
Date: Tue, 12 Oct 2010 12:19:44 +0200	[thread overview]
Message-ID: <4CB43640.2010402@drmicha.warpmail.net> (raw)
In-Reply-To: <loom.20101012T114900-532@post.gmane.org>

Christian Halstrick venit, vidit, dixit 12.10.2010 12:03:
> Can I checkout a certain file to a specific revision without also adding this 
> content to the index? I only want to alter the working-tree - no modification of 
> index or HEAD needed.
> 
> Here is why I need that: I see a bug in git controlled sources. I fix one source
> file and also add one unit test in a separate file. I checked that the test
> succeeds with my fix. The index now contains what I want to commit.
> Now I want to see whether my test fails without my fix. I want to checkout HEAD
> for the source file without destroying my index. In the end, after I saw that my
> test fails without my fix, I just want to say "git commit" without having to.
> 

I would recommend to work on top of a trial commit, i.e.

git commit -m TheFix
git checkout HEAD^ -- fixedfile.c
git reset --hard

and git commit --amend if needed. (Alternatively, use stash.)

You can also use

git show HEAD:fixedfile.c > fixedfile.c
git checkout fixed.file.c
git commit -m TheFix

but I find this more cumbersome.

Michael

  reply	other threads:[~2010-10-12 10:19 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 [this message]
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
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CB43640.2010402@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=christian.halstrick@gmail.com \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.