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

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

flat view

From: Jared Hance <hidden>
Date: 2016-06-15 22:49:46

Stefan Naewe <stefan.naewe <at> atlas-elektronik.com> writes:
On 10/12/2010 12:03 PM, Christian Halstrick wrote:
quoted
Can I checkout a certain file to a specific revision without also adding 
this 
quoted
content to the index? I only want to alter the working-tree - no 
modification of 
quoted
index or HEAD needed.

Here is why I need that: I see a bug in git controlled sources. I fix one 
source
quoted
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
quoted
for the source file without destroying my index. In the end, after I saw 
that my
quoted
test fails without my fix, I just want to say "git commit" without having 
to.
commit the unit test first, and the fix as a second commit ?

Regards,
  Stefan
Just to add to this, since you might not want the test and the fix in separate 
commmits: (as is implied in the message)
  1. commit unit test.
  2. commit fix.
  3. go to detchatched head at HEAD^
  4. run unit test to insure that it fails.
  5. checkout the branch again to where you have the fix.
  6. run unit test to insure that it doesn't fail.
  7. run `git rebase HEAD^` and merge squash the two commits. (optional)

Alternatively, as others have pointed out, the stash should work as well.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help