1

I am in a bit of a situation regarding my dev branch having a different history than my master, despite both of them containing the same content due to a squashed merge.

On Github, I used the "squash and merge" option on my pull request from my dev branch to master. This has resulted in a separation between master and dev that doesn't actually exist. According to Github, my dev branch is a number of commits ahead of master despite those commits being squash-merged into master.

Furthermore, the various merges I've done onto master from dev do not exist on dev and thus dev is also behind master. Including a commit that exists on master that I have not merged onto dev because I know that will only make things worse.

dev compared to master

How do I resolve this issue? Ideally, since both branches are in fact the same (except 1 commit on master that should be ahead of dev) how do I synchronize these branches?

I can update my question with more information if more is needed to help understand my tree.

UPDATE: I have found a similar problem here and I believe it is indeed the squash that has caused this confusion. I am afraid I will have to revert the merge and perform it again without squashing so that Github can correctly understand the history of the two branches.

I could alternatively squash the commits on the dev branch itself and re-merge just the one commit, as I would prefer, but that sacrifices the history of the branch. I think I need to decide between one of these two approaches. Is there another way?

Psymøn
  • 413
  • 2
  • 4
  • 15

1 Answers1

2

I could alternatively squash the commits on the dev branch itself and re-merge just the one commit, as I would prefer.

If you do a PR from the pushed dev branch to master, and merge-squash it... then your local dev should effectively be reset to the new master state.

git fetch
git branch old-dev dev
git checkout -B dev origin/master

You can then go on from the new dev branch

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Indeed, I suspect the best option might be to discard the current dev branch's history and work from the squashed history. That's where my problem lies, I think - I hoped that Git/Github would recognise the 1 merge commit on `master` as a collection of commits on `dev` but instead they are considered completely separate, unrelated commits, creating this divergence in history. – Psymøn Dec 13 '18 at 05:53
  • @Psymøn Yes. I have kept the old dev history in a local branch "old-dev", if you need it. – VonC Dec 13 '18 at 05:54