Git filter-tree helpfully stored a backup in .git/refs/original/refs/heads/tmp. But I can’t find any instructions on how to restore from it. I haven’t touched the repository since then – I just changed my mind about the wisdom of that particular manipulation.
I’m guessing the answer is either a file copy or git update-ref, but these are pretty destructive operations, and I don’t want to get it wrong.
Here’s the thing to know, from which all else flows: except when doing
git gc(well, and thingsgit gcdoes as well), git never removes anything, it only ever adds new things.Let’s say you have a branch that looks something like this:
(this is snipped and slightly modified output from
git lola: http://blog.kfish.org/2010/04/git-lola.html). Now say I did something to my “resubmit” branch, like an incorrectfilter-branch, so that I have two new commits on that branch (1234567 and 7654321, or whatever). I realize, oh no, I did something completely broken, and I want “resubmit” to go back to pointing to commit 2afb8a0, which is the original tip of that branch.That commit is still in git, and will be for several months at least (longer because you have the user-visible branch-name
original/refs/heads/tmp—try doinggit logon it for instance, you’ll see it’s there). Find the commit ID—easy in your case, it’s namedoriginal/refs/heads/tmp—and make your branch point there. If you didn’t have a name, you could dogit branch -d resubmitand thengit branch resubmit 2afb8a0(for my own example above), but you do, so:will delete your current
tmpand rename the renamed one back totmp.(The new commits
filter-branchrecently added, that you decided you don’t like after all, will still be in your repository. Once you’ve deleted the user-visible-names they’ll expire in about 3 months, after whichgit gcwill remove them.)