Git is one of the most common source-control systems that enable software developers in all industries,
enabling multiple team members or colleagues to work concurrently and simultaneously on projects. This is known as Version control systems
which are all about managing contributions between multiple distributed developers.
So,since many users are simultaneously working from different places on the same file, however, this may end up with a merge conflict. This article explains the basics of Git merge
conflicts and this is where Git merge command is involve to resolving a Git merge conflict.
I would like to show the common git commands used to resolve merge conflict.
Basic Git Commands are:
git init
git add
git commit
git status
git merge
git push
git pull
git reset
git checkout
git diff
Conflicts in Git environment generally arise when two people have changed the same lines in a file, or if one developer deleted a file while another developer was modifying it. In these cases, Git cannot automatically determine what is correct.
So, this Conflict is only made known to the team that conducting the merge, the rest of the team is unaware of the conflict.
Git will mark the file as being conflicted and halt the merging process. It is then the developers' responsibility
to resolve the conflict.
Categories of merge conflicts
When contemplate of resolve merge conflict, know that there are two stages involved at a separate points.
When starting and during a merge process.
Starting the Merge Process:
In this case, if there are changes in the PWD (working directory) in the current project, merging won’t start.
So, conflicts happen due to pending changes that need to be stabilized using the Git commands.During the Merge Process:
In this stage failure indicates that there is a conflict between the local branch and the remote branch during the merge process.
In this case, Git resolves as much as possible, but there are things that have to be resolved manually in the conflicted files.
Now, let us look at how to resolve it.
How to Resolve Merge Conflicts in Git?
These are a few steps needed to resolve merge conflicts in Git.
Open the conflicted file and make any necessary changes.
After edit and make the necessary change in the file, we can make use of the git add. a command to stage the new merged content.
The final step is to create a new commit with the use of git commit command.
Then, Git will create a new merge commit to complete the merge.
Let us now look at the Git commands that perhaps we may use to resolving the conflict.
1. git log --merge
This command helps to populate the list of commits that are causing the conflict.
2. git diff
This helps to identify the differences between the states repositories or files.
3. git checkout
It is used to undo the changes made to the file, or for changing branches.
4. git reset --mixed
It also is used to undo changes to the working directory and current folder
5. git merge --abort
This command helps in exiting the merge process and returning back to the state before the merging began.
6. git reset
It is used at the time of merge conflict to reset the conflicted files to their original state.
Top comments (0)