Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop getting extra merge commit every time

I have a project where I am the only developer, with develop and master branches. Every time I merge develop into master, I'm getting an extra merge commit. I think this is because it is not doing a FF merge for some reason. But the code in the develop and master branches is identical. I'll add a new feature to develop branch, often one commit, then after testing merge it to master. And every time I'm getting these extra commits (which also makes develop branch look like it's 15 commits behind master).

I have a few other projects I'm running the same way, and I'm not getting the extra commits on those. So it appears I've done something to this project to cause it to create these extra merge commits every time. Any idea how to stop getting these extra commits? I've done everything except blow away the develop branch and create it again from current master.

Bonus question, is it possible to clean up the history by essentially removing the merge commits without squashing or removing the additional commits accompanying them? I've considered blowing away the MASTER branch and creating it again from develop (since it doesn't have the extra commits) but I'm not sure that's a good idea.

enter image description here

like image 456
billoverton Avatar asked Sep 16 '25 06:09

billoverton


2 Answers

You can only fast-forward master to develop if develop is "based" on master (by going back from the commit develop points to it should be possible to reach the commit master points to).

Looking at the picture, it is very likely that at the moment master points to 28b73893 but develop is still at aeb743f1. If you make a commit in develop, the fast-forward will not be possible.

To solve that, merge master back to develop. This will be a fast-forwarding merge. After that, master and develop will point to the same commit; and it will be possible to make a commit in one branch and fast-forward the other branch.

like image 114
user28667 Avatar answered Sep 19 '25 01:09

user28667


You need to use the rebase command.

If you want the history of your branches to look linear, what you want to do is:

  • Commit on Development branch: git commit -m "FeatureX on Dev"
  • Rebase with up-to-date master: git fetch origin master:master, git rebase master
  • Test your code
  • Happy? Rebase master onto Development and force-push: git checkout master, git rebase Development, git push -f

PS: Rebase is dangerous since it rewrites the history of the branch (steps 2 and 4 above), unless:

  • You know exactly what you are doing
  • No one else pulled the old history

For both, you should be good.

Specific to Azure-Devops:

Under Repo->Commits, if you click on the filter icon and choose "First Parent", it will hide the merges automatically. Try and see if Github has the same?

enter image description here

like image 25
Khalil Khalaf Avatar answered Sep 19 '25 03:09

Khalil Khalaf