Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git merge squash and recurring conflicts

I have a git repository with master and alt branches. alt branch contains modified version of master code, and i am trying to merge changes from master to alt like this:

git merge --squash master 

Merge results in conflict:

Auto-merging myproject/foo/bar CONFLICT (content): Merge conflict in myproject/foo/bar Squash commit -- not updating HEAD Automatic merge failed; fix conflicts and then commit the result. 

After I resolve conflicts and commit changes everything seems fine, but when i run git merge --squash master again (without doing any changes on any branches) i will get same conflict error.

Why is that? What did i miss?

like image 312
draganHR Avatar asked Aug 03 '12 14:08

draganHR


People also ask

Why do I keep getting merge conflicts?

Often, merge conflicts happen when people make different changes to the same line of the same file, or when one person edits a file and another person deletes the same file. You must resolve all merge conflicts before you can merge a pull request on GitHub.

Is it better to squash and merge?

You should consider using squash if your team prefers a linear project history. This means that the history held by your main branch should not contain merges. A squash merge makes it possible to keep changes condensed to a single commit, supporting this strategy nicely.

What happens if you get a conflict during a merge?

A merge conflict is an event that occurs when Git is unable to automatically resolve differences in code between two commits. When all the changes in the code occur on different lines or in different files, Git will successfully merge commits without your help.


1 Answers

By squashing the merge, you've created a commit which has the effect of, but is not really, a merge.

That is, the working tree has the modifications you'd expect, but the metadata doesn't: crucially, the commit doesn't have two parents (one on master and one on alt) and therefore subsequent merges can't figure out the last common ancestor.


Useful uses of squash

  1. merging a completely finished feature branch onto master. I'll accumulate any useful information into the squashed commit, but specifically don't want this feature's incremental development history polluting the master commit timeline.
  2. merging several independent features (or contributions from different developers) onto the same integration branch, again without preserving their incremental histories. I could rebase them all together, and then use rebase -i to squash their commits, but this is easier

Useless uses of squash

Any merge where you want to keep the history and ancestry metadata intact, such as any time you want repeated recursive merges to work correctly, specifically what the OP is trying to do.

squashjust isn't really a good default, which is why it isn't the default.

like image 92
Useless Avatar answered Oct 19 '22 11:10

Useless