How to solve merge conflict in Git?

When merge with master branch, conflict comes (in fact, it's very common). I need to resolve these conflicts manually.

Solution:

When conflict occurs, we need to open the conflicted files, and they look like this:
class ConflictDemo
{
    public static void main(String args[])
    {
<<<<<<< HEAD
        String versionControl = "SVN";
=======
        String versionControl = "Git";
>>>>>>> master
        System.out.println(versionControl);
    }
}
A conflict-marked area begins with <<<<<<< and ends with >>>>>>>. These are also known as the conflict markers. The two conflicting blocks themselves are divided by a =======. The first section is the version of the current branch head. The second section is the version of master branch.
We have several options here. We can either keep our changes, take our coworker's changes, or make a brand new change. (Whatever you do, you need to make sure to resolve the conflict such that the file makes sense, and everyone is happy.) After we edit the code and resolve this conflict, we can now git add this file, commit the change with a new commit message.
git add ConflictDemo.java
git commit -m "Merged master fixed conflict."

No comments:

Post a Comment

Genuine websites to earn money.

If you are interested in PTC sites then this article is for you. I have personally tried many of the sites and found that the best thing ...