On Thursday, March 14, 2013 6:28:36 PM UTC-7, joeri...@gmail.com wrote:
> On Thursday, March 14, 2013 11:54:36 AM UTC-7, Konstantin Khomoutov wrote:
>> On Thu, Mar 14, 2013 at 11:24:27AM -0700, joeri...@gmail.com wrote: 
>> > How do I reset one working file, but leave the index alone?  git 
>> checkout 
>> > file does not do that 
>> > (it appears to do nothing), nor does git checkout -- file. 
>> > 
>> > To clarify, I've edited a file, then added it to the index. I now want 
>> to 
>> > leave the change in the index, 
>> > but reset the working file to the checked-in version.   
>> git checkout HEAD -- file 
> That does not work.  It resets the index and the working space. 

It is surprising that this doesn't work, the help page for checkout 
specifically discusses this case. 
Regardless, it doesn't work, the version of file that was added to the 
index no longer exists in the index.
To demonstrate that it doesn't work, do the following

tmp $ mkdir git-test
tmp $ cd git-test
git-test $ git init
Initialized empty Git repository in /home/joe/tmp/git-test/.git/
git-test $ echo 'one line' > file
git-test $ git add file
git-test $ git commit -m 'initial commit'
[master (root-commit) 8fad1ad] initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 file
git-test $ echo 'second line' >> file
git-test $ git add file
git-test $ git checkout HEAD -- file
git-test $ git status
# On branch master
nothing to commit (working directory clean)
git-test $ cat file
one line


>> or 
>> git show HEAD:file >file 
> This does work.  Seems slightly crude, but better than nothing. 
>> `git checkout -- file` did not work for you because if you don't specify 
>> where to get the contents from, it assumes the index -- to cite the 
>> manual: 
>>   When <paths> or --patch are given, git checkout does not switch 
>>   branches. It updates the named paths in the working tree from the index 
>>   file or from a named <tree-ish> (most often a commit). 

You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to