Search code examples
gitbitbucketmerge-conflict-resolutiongit-fork

Discard a messed up git fork in Bitbucket


For development purposes, I work with a fork of the main project. Every now and again, I pull in the parent repo:

git fetch parent
git merge parent/master

On this occasion, there had been a lot of work done by others, so when I did that, I pulled in 147 commits, so git status showed that I was well ahead of origin (my fork). I did a bit of work. I had made five commits, but I wanted to squash the last two into one commit. The usual trick here is to do git rebase -i, and then edit the last message to squash. I did this.

When I saw how massive the list was, I exited without saving changes. Squashing the two commits into one wasn't really that important, so I abandoned the idea. However, git still ran through the list of commits, redoing all of them, which took a long while.

When I pushed, and then opened a pull request on Bitbucket, Bitbucket tried to apply all of the commits, not just the ones I'd done myself. And since other changes had been made since, this resulted in a bunch of merge conflicts in code I hadn't touched.

Is there any neat way to resolve this? I'm thinking of nuking my fork and reforking (none of my branches contain anything valuable), but perhaps there's something less destructive I could try?


Solution

  • You could just nuke individual branches in your fork and reset them to where the parent is:

    git fetch parent
    git checkout master
    git reset --hard parent/master
    git push -f
    

    That way, you will still have the few commits you want to keep, and you'll be able to cherry-pick them afterwards, via branches they are on or via the reflog.