An Automatic Merge Failure occurs whenever there are competing changes made to the same line by two developers, or when one developer is working on a file and another developer deletes it. Merge conflicts are relatively common whenever you commit.
It is essential to identify and resolve conflicts. Here is a step-by-step guide on how to deal with Automatic Merge Failure.
Open git bash and go to the repository in which the merge conflict arose:
cd {RepositoryName}
Write git status
to generate a list of files that have a merge conflict.
Open the highlighted file using the git status
command in an <<<<<<<
, =======
, and <<<<<<<
.
You will find something like this:
<<<<<<< HEAD
abc123
=======
def456
>>>>>>> branch-ed
<<<<<<< HEAD
shows the change made from the base branch.=======
separates the conflicts.>>>>>>> branch-ed
shows the branch where the conflicting change was made.In this example, there is a conflict in the same line of code; the base branch wrote abc123
, whereas, the branch branch-ed
wrote def456
.
Decide which version you want to incorporate: base branch one, sub-branch one, both, or a new one. Make the changes to the file and save them.
Suppose you want to change the branch-ed
: go to that branch, change def456
to abc123
, and save the file. Add the file as you go:
git add
Commit your changes and add a comment to highlight the change made manually:
git commit -m "Changed branch-ed from def123 to abc123"
Free Resources