Skip to contentSkip to conversation

Simple problem

DISCUSSION Kenneth P. Turvey 4 participants 5 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

I ran into an issue earlier today that I didn't know how to easily solve in git. I'm sure it is easy to handle, but I wasn't sure how.

I removed a file and then realized I'd hit the wrong one. So all I wanted to do was to get the file back the way it was in the last commit.

Basically I wanted something similar to:

svn update myfile

in subversion.

I got it back by using a diff and just deleting all the minus signs at the beginning of the lines, but I'm sure this isn't the way to handle this. Strangely this simple case wasn't covered by any of the tutorials I looked at.

Thanks.

Signature · 1 line
Kenneth P. Turvey <[email protected]>
#1 lore raw
Quoted 8 lines · On Monday, April 28, 2008 at 16:31:05 (+0000) Kenneth P. Turvey writes:

I ran into an issue earlier today that I didn't know how to easily solve in git. I'm sure it is easy to handle, but I wasn't sure how.

I removed a file and then realized I'd hit the wrong one. So all I wanted to do was to get the file back the way it was in the last commit.

Basically I wanted something similar to:

Quoted 8 lines

svn update myfile

in subversion.

I got it back by using a diff and just deleting all the minus signs at the beginning of the lines, but I'm sure this isn't the way to handle this. Strangely this simple case wasn't covered by any of the tutorials I looked at.

% rm file
[oops]
% git checkout file

Bill

#2 lore raw
Quoted 13 lines · Bill Lear
Quoted 12 lines · On Monday, April 28, 2008 at 16:31:05 (+0000) Kenneth P. Turvey writes:

I ran into an issue earlier today that I didn't know how to easily solve in git. I'm sure it is easy to handle, but I wasn't sure how.

I removed a file and then realized I'd hit the wrong one. So all I wanted to do was to get the file back the way it was in the last commit.

Basically I wanted something similar to:

svn update myfile

in subversion.

Quoted 8 lines
Quoted 4 lines

I got it back by using a diff and just deleting all the minus signs at the beginning of the lines, but I'm sure this isn't the way to handle this. Strangely this simple case wasn't covered by any of the tutorials I looked at.

% rm file
[oops]
% git checkout file

That restores the version from the index, so it will fail if you did "git rm file". To get the file from HEAD use "git checkout HEAD -- file".

Björn

#3 lore raw

On Mon, 28 Apr 2008 18:49:45 +0200, Björn Steinbrink wrote:

[Snip]

Quoted 3 lines

That restores the version from the index, so it will fail if you did "git rm file". To get the file from HEAD use "git checkout HEAD -- file".

Thanks. I tested this and it works as advertised. I took a look at the man page and I understand what the -- is for too.

I had actually tried:

git checkout myfile.java

and this didn't work.

Signature · 1 line
Kenneth P. Turvey <[email protected]>
#4 lore raw
In reply to Kenneth P. Turvey

Kenneth P. Turvey, Mon, Apr 28, 2008 18:31:05 +0200:

Quoted 10 lines

I ran into an issue earlier today that I didn't know how to easily solve in git. I'm sure it is easy to handle, but I wasn't sure how.

I removed a file and then realized I'd hit the wrong one. So all I wanted to do was to get the file back the way it was in the last commit.

Basically I wanted something similar to:

svn update myfile

git checkout HEAD filename

but mostly just "git checkout filename"