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:
- Find the offending commit with git log or git log -p, not the revision number prior to the catastrophic change.
- View the file at that point in time with git show SHA-ID:path/to/file
- Replace current copy with git show SHA-ID:path/to/file > path/to/file
- Verify the damage has been undone with git diff
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.