Search code examples
gitgithubpull-requestsquash

Unable to create pull request after new fork squashed original commits


I've forked a project on GitHub. I need to squash the original commits before making changes/commits to my forked project. However, I wondered if I would be able to create a pull request in order to merge my changes back to the original project. Can this be done?

I tried to do it in a test project but it seems to be the case that I can't do the pull request as the network shows that the two projects are no longer connected. Here is what I did:

  1. Created a test project ("original project")
  2. Created a new file, committed, and pushed
  3. Created another file, committed, and pushed
  4. In another account, I forked the test project ("forked project")
  5. In the forked project, I squashed the git log that had 3 commits (Ran 'git rebase --root -i' then 'git push origin master --force')
  6. In the forked project, I modified one of the files, committed, and pushed. This is the first change to the fork.
  7. Tried to do a pull request on GitHub to merge the change from #6 from the forked project to the original project but said "There isn't anything to compare. original:master and forked:master are entirely different commit histories."

The network looked like the following:

original    forked

   o                (git init)
   |
   o                (add file)
   |
   o                (add file)

               o    (squashing commits)
               |
               o    (update file)

Maybe I did something wrong? Or my setup is incorrect? Or it just can't be done...


Solution

  • I confirm: the PR needs to be done in a dedicated branch, based on a common history between the original repo and the fork.

    If you squash the first commits, you change that common history.

    You need to communicate with the original project in order for his/her owner to make the required changes.
    Then you can fork that repo, and make new PRs.