When merging (or rebasing) a branch into (or onto) another, git usually tries to be smart and automatically merges changes if it can. It will show conflicts only when it can't automatically merge commits. However, this automerge isn't always right. Especially, if there are multiple changes within a single file git will automerge a few of them and show merge conflicts in others. This usually doesn't work very well because those other changes (that git automerged) are related to the conflicting changes and so you need to consider the entire changeset while fixing the conflict. But if git has automerged those changes you won't even notice that while fixing the conflict.
To avoid above situation I would like to know if there is a way to tell git (that during a merge or rebase) do not automerge anything in a file which has a conflict?
CodePudding user response:
Especially, if there are multiple changes within a single file git will automerge a few of them and show merge conflicts in others
I totally know exactly what you mean. You can wind up with your code in the wrong method!
But no, there's nothing you can do. You just have to read really carefully when you to the merge conflict resolution. It will help a lot if you turn on the 3-way diff option:
merge.conflictstyle=diff3
This shows you what both wings of the merge started with (the merge base), so you can see what each is trying to do it. This will help you work out what needs changing as you resolve the merge.
CodePudding user response:
This is your merge tool's doing. Use one that shows you all four versions (base, our, theirs, so-far) like vimdiff
does and you see everything, including the proposed automerges and where they came from.