Skip to contentSkip to conversation

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

DISCUSSION [email protected] 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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...

So how modify

git checkout <commit> <file>

to do this?

cs

#1 lore raw
Quoted 2 lines · [email protected] 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
#2 lore raw
Quoted 2 lines · Junio C Hamano
    $ git checkout HEAD~43 Makefile
    $ git reset Makefile

Thank you very much. git reset looks that just what I need.

cs

#3 lore raw
In reply to [email protected]
Quoted 10 lines · On Tue, Jan 6, 2009 at 1:18 PM, <[email protected]> wrote:

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...

So how modify

git checkout <commit> <file>

to do this?

I have a stupid way to do this:

 $ git show v2.6.12:Makefile > Makefile
 $ git diff --cached  /* no outputs */

Ugly but seems work.

Signature · 2 lines
Thanks,
Jike