What is the right command to get a local copy of a specific version of a single file ?
With other revision tools like CVS/SVN, a specific revision number is assigned to a file every time a checkin happens. I don't see that with Git.
During software development a developer might checkin a file multiple times. But if he/she wants to release a specific ver to Production, what git command do I use to be able to pull out a copy of a specific ver of a file ?
Note: I do not want to latest ver on the branch or tag, but an intermediate specific ver.
Solved! Solved! Go to Solution.
Git has various commands to do that. If you want to retrieve that copy without affecting the currently checked out files,
is the command you're looking for. For example, to retrieve the file git.c at the revision tagged v2.0.0, you would do:
git show v2.0.0:git.c
Before the colon, any revision specifier can be used (such as a sha1, a tag or a branch name). After the colon, you put the path to the file you want.
Thanks for the reply.
I tried show command and it works. However I dont see any revision number listed against each commit as per your example.
I see the SHA value listed against each commit which is a 40 character string, and can get a copy via this
git show 85178a160119aa82681e560a63fc217fb7681de9:<file>
Is there any setting that I need to turn on which will start labelling revision numbers in place of the SHA value ?
Git doesn't have revision numbers, as they don't really make sense in Git's branching and merging model. The sha1's are unique identifiers for commits, most commands (including git show) will accept an abbreviated version of the sha1 as well for more readable commands. In your example you could use 85178a1 as identifier for instance.
This is very easy indeed with SmartGit (which is why I rarely used command line).
Look at this:
If I click on "Log" (top right) I get this:
Now I can select some arbitrary commit, say 5E74C789, I can then see the files in that commit on the right hand side:
Now the powerful part, here's what I get if I right click a file - say SmartPointer.cs:
You can see "Save As..." if I click that I get this:
So I can save the file as it looked before that commit or after the changes that were made in that commit.
This is extremely helpful for those ocassions where you simply want to "restore" a single file to some earlier state, you may have made hundreds of changes over many commits but then decide "You know, that constants file with hindsight should have been left alone on this project and the stuff put into a new file" for example.
This is a huge help on those rare ocassions when one wants to do this, in effect this is letting you revert changes to individual files even though those changes might be mixed up with other files.
You do of course get prompted if the file exists when you try to save, letting you verifty that you do indeed want to overwrite the current file, and of course once you do save it you then simply commit that as a change say "Reverted file to its state at XXX".