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

Re: How make "git checkout <commit> <file>" *not* alter index?

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 6, 2009, 06:26 UTC
Message-ID
<7vk599ne6a.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090106051852.GA3278@seberino.org>
chris@seberino.org writes:
> I want to pull an old version of a file into my local directory and make it
> appear like work I haven't added to index yet...

The command to reset the index can be used any time you have unwanted changes to it and pretend you started from the latest commit (aka HEAD).

Typically, you use it to recover from a "git add" you did by mistake, e.g.

    $ edit frotz.c nitfol.c
    $ git add frotz.c nitfol.c
    ... oops, I do not want the changed frotz.c in the next commit.
    $ git reset frotz.c
    $ git commit -m 'update nitfol.c for such and such reasons'

This procedure can be used after you have smudged the index in an unwated way, and is not limited to "git add" (or "git add -p"). In this case, you can do:

    $ git checkout HEAD~43 Makefile
    $ git reset Makefile
Previous: Jike SongNext: chris@seberino.org
Message 3 of 4 in “How make "git checkout <commit> <file>" *not* alter index?”
  1. chris@seberino.orgJan 6, 2009
  2. Jike SongJan 6, 2009
  3. Junio C HamanoJan 6, 2009
  4. chris@seberino.orgJan 7, 2009

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.