Thread (13 messages) 13 messages, 9 authors, 2016-06-15

Re: Can I checkout a single file without altering index?

From: Michael J Gruber <hidden>
Date: 2016-06-15 22:49:45

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help