Pluck out an old revision of a file with git show 3

Posted by Kenneth Kalmer on March 20, 2009

I was busy merging work back and forth between topic branches today and by accident miss-merged a 700-line spec. Everything else was fine (or so I hope) except this one file. I couldn’t use git revert, since that would mean I’ll have to redo all the merges I made.

So in panic I googled and read several man pages, coming to the following conclusion that worked quite well:

  1. Find the offending commit with git log or git log -p, not the revision number prior to the catastrophic change.
  2. View the file at that point in time with git show SHA-ID:path/to/file
  3. Replace current copy with git show SHA-ID:path/to/file > path/to/file
  4. Verify the damage has been undone with git diff
  5. Commit
  6. Breathe

Git is a double edged sword, it is extremely powerful and useful, but can be a real pain in the behind. I love git, and will not easily be convinced to move to something else.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Andrew Timberlake Fri, 20 Mar 2009 16:33:08 UTC

    Thanks for this, nice to have another get out of jail free card when I need it

  2. Kenneth Kalmer Fri, 20 Mar 2009 17:08:49 UTC

    Yip, blogged it so I can’t loose it :)

  3. Josh Tue, 03 Nov 2009 00:23:09 UTC

    One important thing to note is that the path to the file specified has to be the path relative to the root of the git repository. It can’t be a relative path :(

    Seems silly to me, but there you have it.

Comments

  • Tags

    activerecord air amqp analytics audits bash bind capistrano cheat convert couchdb daemon-kit dlz dns elsewhere gentoo gist git hoptoad linux macros mercurial messaging mysql nginx olympics plugins postfix postini powerdns presentations projects quickies rails rake review ruby ruby19 ruote security shoes sitemap ssl svn webby
  • Recent Posts

  • Archives

  • Alltop. Seriously?! I got in?