1

I wonder when exactly a merge conflict occurs. My assumption is that it occurs when a file was modified in both branches. In more details, if a file was modified in one branch but not in another one, the "modified" version will be used (the "old" version is replaced by a "new" one).

If there are two "new" versions (coming from two branches), git does not know what version to use, so a manual merge is required.

However, I am not sure about my understanding. I can imagine that even if the same file was modified in both branches there is no merge conflict if the modifications are done to places that are far enough from each other.

Roman
  • 124,451
  • 167
  • 349
  • 456
  • 2
    Possible duplicate of [when exactly does a git merge conflict arise](https://stackoverflow.com/questions/42693608/when-exactly-does-a-git-merge-conflict-arise) – 1615903 Nov 05 '17 at 15:00

2 Answers2

4

Merge conflicts raised when a line (or lines) in a file is edited by more then one person at the same time. Doesn't necessarily have to be in 2 different branches.

After the first one pushes his changes, any other who will try to push his changes will stumble upon a merge conflict.

Basically the git system can handle merging alone. But in this scenario it cant tell which edition is the right one thus raising a merge conflict.

See this post for more info: when exactly does a git merge conflict arise

1

A merge conflict happens in git when try to modify same lines by different people and it can't be merged automatically into a branch.

For example, two teammates forked same repo and did modifications in their local branch and created a pull request to master. Say line number 10 was modified by both.

If first person's changes have been merged into upstream and if second person's pull request is still open, it will show that changes can't be merged automatically since there is a merge conflict because both changes are been made to same line and second guy's branch doesn't have changes made by first guy.

In this case we have to manually fix the merge conflict. Refer the link https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ to see how to fix it manually from command line

slashpai
  • 1,141
  • 7
  • 12