git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jared Hance <jaredhance@gmail.com>
Date
Oct 13, 2010, 17:09 UTC
Message-ID
<loom.20101013T190544-893@post.gmane.org>
In-Reply-To
<4CB44318.7000305@atlas-elektronik.com>
Stefan Naewe <stefan.naewe <at> atlas-elektronik.com> writes:
> 
> On 10/12/2010 12:03 PM, Christian Halstrick wrote:
> > 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.
Show 5 quoted lines
> 
> 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.
Previous: Stefan NaeweNext: Alex Riesen
Message 4 of 16 in “Can I checkout a single file without altering index?”
  1. Christian HalstrickOct 12, 2010
  2. Michael J GruberOct 12, 2010
  3. Stefan NaeweOct 12, 2010
  4. Jared HanceOct 13, 2010
  5. Alex RiesenOct 12, 2010
  6. Tomas CarneckyOct 12, 2010
  7. Christian HalstrickOct 14, 2010
  8. Neal KreitzingerOct 15, 2010
  9. Jonathan NiederOct 15, 2010
  10. Jeff KingOct 15, 2010
  11. Jonathan NiederOct 15, 2010
  12. Jeff KingOct 15, 2010
  13. Neal KreitzingerOct 15, 2010
  14. Andreas SchwabOct 15, 2010
  15. Junio C HamanoOct 15, 2010
  16. Jonathan NiederOct 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.