Search code examples
gitpull-requestgit-fork

Is there a way to squash commits in fork after pull request was accepted to original repo?


I have a fork of repository where I'm writing my parts of code. I made quite a mistake of writing pieces of code (usually it's a kind of ~50-100 lines of sql code) into master branch of fork (I didn't realise it at the time though) and then pull requesting master branch of fork into master branch of origin.

Settings in original repo allow me only to squash and merge commits. So right now I'm in the situation where every pull request is like 60 commits and 1 file changed (the actual I worked on).

Is there a way to somehow sync states of original repo and fork, to remove all unnecessary commits from master branch?


Solution

  • After some research, I managed to find workable solution:

    • Find a commit hash before your first commit
    • git reset --hard
    • git push -f origin master
    • git pull upstream master
    • git push origin master

    And my fork (origin here) is synced with upstream.