Git is such a popular Version Control System. It needs no introduction.
Software development is a collaborative task where git helps track and versions the changes made. When working in a team setting, conflicts are frequent visitors. I am not refferring to people coming to blows, but Git encountering lines in files that have received edits from two branches during a merge operation.
Therefore a git conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other.
When you inspect an affected file in a merge conflict, there are strange symbols that appear in the lines where the conflict has occured. Ideally when git encounters a conflict during a merge, it will edit the content of the affected files with visual indicators that mark edits received from both sides of the involved branches.
These symbols are <<<<<<<
, =======
and >>>>>>>
, like in the example illustration below of a merge conflict:
What these symbols mean
Its simple.
=======
is a symbol that separates edits recived from both branches. The content above and enclosed between <<<<<<<
, and =======
is the receiving branch. More specifically the branch that is currently checked out and receiving work from another branch.
And the content below =======
, enclosed between =======
and >>>>>>>
, is the merging branch.
It is helpful to search a project for these symbols during a merge to find where conflicts need to be resolved.
To fix a conflict, you as a developer has to decide which either side of the =======
symbol you want to stick with. Once decided, you can replace the symbols with the content you have chosen. Once you are certain you have fixed all the conflicts pointed out by Git, you can mark resolved by runnig git add
on the file(s) and finally git commit
to complete the merge operation.
If somehow later this merge turns to be a mistake, you might want to equip yourself with git techniques to undo. I wrote an article that teaches exactly that: how to undo mistakes in Git.
Thanks for reading.
Top comments (0)