Reconcile commits with different hashes

Viewed 114

Plot: I have a local develop and master branches. develop has around 90 commits ahead of master, spawning from ~6 months back.

I ran a git filter-branch -f --index-filter 'git rm --force --cached --ignore-unmatch media/*' -- --all command that rewrote more of git's history than I was expecting, on both branches. This, because of what the command does, actually made a gazillion git operations, which left my git reflog useless.

I recovered the master branch easily with a simple git reset --hard origin/master, but my develop branch is in a really bad shape.

Now, obviously, the commits hashes between master and develop don't match, which makes git think that I have a gazillion commits to push and a gazillion commits to pull from/to my remote/develop (there should be 0 commits to pull, ~90 commits to push)

Is there a way I can make git "reconcile" all the commits from master and develop? It should be something like:

for commit in commits_in_master:
    tmp = search_by_commit_autor_and_date_and_message_in_develop(commit)
    tmp.hash = commit.hash
    tmp.save()

Edit:

If what I'm asking is not possible, can I (somehow) extract only the ~90 commits that weren't pushed to origin/develop, then git reset --hard origin/develop my develop branch and then apply those ~90 commits?

2 Answers
git fetch -u . '+refs/original/*:*'
git reset --hard

will put everything back to its committed state before the filter-branch.

Before running filter-branch, Git creates a backup of all your current branch heads. They are stored in the refs/original namespace. You can reset your branches to point to the old heads again (having a backup of your full repository does not hurt before resetting your branches. Better be safe than sorry):

git branch -f develop original/refs/heads/develop

The original namespace has the same layout as your regular refs directory.

Related