Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does git have (or need) the equivalent of svn's peg revision?

Tags:

git

svn

Say I follow these steps in svn:

rev 1: create a file called 'foo'
rev 2: delete 'foo'
rev 3: create a new file called 'foo'

If I want to see the contents of the first 'foo' using svn, I would need to use the peg revision syntax 'svn cat foo@1' since the traditional syntax 'svn cat -r 1 foo' would fail.
I've read that git tracks content and not files, so does that mean there's no need for something like a peg revision?

like image 395
Ravi Avatar asked Jan 30 '11 01:01

Ravi


1 Answers

git show HEAD~1:/path/tp/foo

will show you the content of the file as it was in "rev1" (note: you need to specify the full path of the file, from the root directory of the Git repo)

As mention in "Restore a deleted file in a Git repo", you can quickly restore a previous version of a file with a checkout.

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"

(with $file being the full path of the file from the root directory of the current Git repo.)

like image 162
VonC Avatar answered Nov 11 '22 11:11

VonC