1

I'm playing with GitHub actions and testing a commit linter on a PR (from a dummy branch called meh to master), which I managed to make it work, except that I needed to change my previous commit messages (which were already pushed at that point) in order to match the commit linter regex (which uses conventional commit).

So I went with a git rebase -i --root and reword-ed every commit since the very beginning and then I pushed the commits to my branch meh, except that when I did that the PR closed automatically, I can't reopen or create a new one (from the same branch meh to master) cause according to GitHub:

The meh branch has no history in common with master.

How can I re-open my PR?

Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
  • Not too surprised. I cloned your repo, and (on `master`) tried to do a `git merge meh` and it told me `fatal: refusing to merge unrelated histories`. If a merge would fail in this way, then a pull request can't make sense. – alani Jun 19 '20 at 23:57
  • @alaniwi Yea and that's the reason why my question is how to fix that? – Natalie Perret Jun 20 '20 at 00:00
  • It seems that there is a non-default option called `--allow-unrelated-histories` which will allow the merge, so maybe you do that locally, commit to a new branch, push that new branch, and then do a PR from your new branch. – alani Jun 20 '20 at 00:02
  • @alaniwi thanks will try this out, fingers crossed =| – Natalie Perret Jun 20 '20 at 00:03
  • Trying the merge with your actual repo gives a couple of merge conflicts to resolve, but it permitted the merge in principle. – alani Jun 20 '20 at 00:04
  • More at https://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories-on-rebase – alani Jun 20 '20 at 00:05
  • Too bad GitHub doesn't provide free pre-received hooks, I wanted to test how to modify already pushed stuff, that seems tricky to enforce such commit linting without having people fighting to rewrite the git history every now and then. – Natalie Perret Jun 20 '20 at 00:05
  • 1
    @alaniwi what worked for me to re-open the PR: `git pull origin master --allow-unrelated-histories`. Tbs, it kinda messed up the commit linter in fetching the commits. See: https://github.com/wagoid/commitlint-github-action/issues/36#issuecomment-647022955 – Natalie Perret Jun 20 '20 at 18:42

1 Answers1

1

Just like what @alaniwi said, this could be solved with what is described here:

Try the following command:

git pull origin master --allow-unrelated-histories

This should solve your problem.

That being said, you can also mess up the SHA1 of your commits at some point, if you have to git push --force ..., so yea it would work out to re-open the PR, but your CI might scream a little bit.

Natalie Perret
  • 8,013
  • 12
  • 66
  • 129