I created a folder with a single simple text file to play around with Git a bit. First and foremost, I’m interested in merging and rebasing. I need to learn those. However, I discovered that I can’t merge. Here’s a bit of context:
C:\Users\Семья\Desktop\Git playground>git show violet-branch:“Simple text file.txt” Roses are red Violets are blue, blue, blue And some violets are just violet
C:\Users\Семья\Desktop\Git playground>git show master:“Simple text file.txt” Roses are red
Violets are blue, blue, blue C:\Users\Семья\Desktop\Git playground>git log master…violet-branch commit 9e55974f2c8daa7e06806d0dc274e10b93dd5b86 (violet-branch) Author: Sergey [email protected] Date: Sun Sep 17 15:59:09 2023 +0300 some violets
C:\Users\Семья\Desktop\Git playground>git merge violet-branch error: Merging is not possible because you have unmerged files. hint: Fix them up in the work tree, and then use ‘git add/rm ’ hint: as appropriate to mark resolution and make a commit. fatal: Exiting because of an unresolved
conflict.
Why can’t it simply add the third line in the master
branch?
Or, to rephrase it, suppose I have
C:\Users\Семья\Desktop\Git playground>git show master:“Simple text file.txt” Roses are red Violets are blue, blue, blue
C:\Users\Семья\Desktop\Git playground>git show violet-branch:“Simple text file.txt” Roses are red Violets are blue, blue, blue And some violets are just violet
How do I simply merge the third line into master
?
If git doesn’t know how to resolve a merge you have to manually specify what it is. Git’s algorithm will try its best but it has limits.
Also check out this website for learning git: https://learngitbranching.js.org/
But can’t Git just add that extra line? Why is it a merge conflict? It’s another line of text
Well, think of this in the context of coding (although for writing it’s applicable as well). Is adding to the line the correct intended change or is the omission the intended effect? Git has no way of ascertaining that.
Just because a change happened “later” in a different branch, doesn’t mean it works within the context around what the original line intended.
But this is an algorithm as I said, using an algorithm is a strategy. You can customize git settings so that it does prefer the merging branch in all cases. I personally wouldn’t recommend it since it’s not a setting you’d likely run into when working with others (I could be wrong in this, there could be some groups that really enjoy this setting in a group environment).
Merges are typically non-trivial, so if there is a conflict it’s good to have it peer-reviewed by another pair of eyes to minimize errors.
1 Like
What is a conflict to Git? Does it consider a conflict any situation when a file has different content in different branches?
The documentation says (and note this is for basic conflicts
If you changed the same part of the same file differently in the two branches you’re merging, Git won’t be able to merge them cleanly… you’ll get a merge conflict
Although I have been in a scenario where a co-worker and I didn’t co-ordinate ahead of time and his changes structurally changed a lot of places so it made my additions that were already a progress impossible to resolve via normal means, but that’s more on us than it is on git.
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
1 Like
Aren’t the lines different? Or due to the line break it’s actually a third line in both cases?
It can figure out which lines match even when they are shifted (most of the time)