Tuesday, October 11, 2011

Git an Old Revision

I had been working on a branch, happily committing code for a couple of weeks, when I realized I needed to revert one of the files to the state it was in when I branched it.

Uh oh.  How do you do that with git?  To make matters worse, I had also moved the file.


 Fortunately, I hadn't made any changes to the master branch.  That made it a little bit easier than it otherwise would have been.

I won't remember this a few weeks from now when I need it again, so here's how I did it:
_

git show master:org/blah/foo.java > org/blah/bleh/foo.java

_

I used the branch name master, but you can give it any valid identifying value: like an SHA-1 value or HEAD, or even something like HEAD-5 (i.e., HEAD minus 5).

No comments:

Post a Comment