Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
702 views
in Technique[技术] by (71.8m points)

merge - Git does not detect a conflict in code on same line

i am learning git i have the tried the following example : in the master branch i created a file 1.txt that has one line hi then i switched to a new branch "mybranch" and edited the same line to this hello instead of hi when i get back to the master branch and run a git merge command git merge mybranch its doesn't detect that it's a conflict that i should resolve instead it replace the word hi with hello essentially it replaces some code in master branch without letting me know my questions is why didn't git consider that to be a conflict even tho the bitbucket website says

A conflict arises when two separate branches have made edits to the same line in a file

question from:https://stackoverflow.com/questions/65644717/git-does-not-detect-a-conflict-in-code-on-same-line

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The way a merge works in Git, ignoring renames, is that Git considers three points in the history: the heads of the two branches, and the merge base, which is usually the most recent common ancestor. Git merges by looking at the changes between the merge base and each head (usually a branch).

If one side contains a change, such as on mybranch, but the other does not, such as master, then the result of the merge is the change. This is the goal of why one performs a merge in the first place. If both sides have identical changes or neither side has a change, then Git takes the version that's common. A conflict occurs only if both sides have different changes in the same area, since Git then doesn't know what to do.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...