Git Merge and Merge Conflict
Let us discuss what merging in git. Merging means combining changes from one branch into another branch. Now let’s see how can we perform merging here we can see that we can see one log in the master branch.
Merging Changes
Now let’s check out the logs in the dev branch and here we can see there are two logs in the dev branch.
So now as we can see from the commit present in the dev branch a file k.txt is created which means a file by the name of k.txt is created in the dev branch so now if we want that change to be reflected in the master branch for that we can use the command git merge name_of_the_branch.
So now we can see that after using the merge command the changes are getting reflected in the master branch and we can see that a new commit is showing up in the git logs of the master branch which is having a commit message a new file k.txt is created.
Aborting a Merge
So, now let’s see how to abort a merge for aborting a merge we use the command: git merge –abort. Here we can see how we exited from the merging state by using the below command as follows:
git merge --abort
Merge with a Commit
On using the simple git merge command it resolves the merge as fast-forward and only updates the branch-pointer but if you want to create a merge commit for that we have to pass –no-ff as a parameter in the below command.
git merge branch_name --no-ff -m commit_message
Here we can say that it is only updating the branch pointer by showing head-on master.
Merge Conflicts
Merge Conflicts are the conflicts that occur when a developer is editing a file in a particular branch and the other developer is also editing that same file or when developer A edits some line of code and that same line of code is being edited by another developer B that leads to conflicts while merging. Now let’s see how to resolve these merge conflicts.
From the above procedure, we have successfully resolved our merge conflicts between the two branches and understood the concept of merge conflicts.