I started messing around with git filter-branch
. The --all option rewrites all branches and tags. Cool. git filter-branch
creates a backup of all re
Here's a simple and safe way to undo a filter-branch:
git fetch . +refs/original/*:*
If the currently checked out branch (HEAD
) is one of the branches to be restored, this command will fail. You can run git checkout --detach
beforehand to let git fetch
update all branches. Remember to checkout a branch after running git fetch
!
Once the refs have been successfully restored, you can delete the refs/original
refs safely with this command:
git for-each-ref refs/original --format='delete %(refname) %(objectname)' | git update-ref --stdin
Old answer:
git for-each-ref refs/heads refs/tags \
--format='git update-ref "%(refname)" "%(refname)@{1 hour ago}"'
For added safety you could test whether the filter-branch actually did update the ref:
git for-each-ref refs/heads refs/tags --format='
{ git reflog -1 "%(refname)" | sed -n "/filter-branch: rewrite$/Q1"; } \
|| git update-ref -m "reset to before filter-branch" \
%(refname) %(refname)@{1}' | sh -x