Backlog uses cookies to deliver our services. By visiting our website, you agree to the use of cookies as described in our Cookie Policy.

During some merge conflicts, the source code will not be able to be merged automatically. You'll need to manually fix the issue as follows.

1. Create the initial state

First, we need to reproduce the situation where the conflict occurs. We can make a conflict happen by using the equality operator (==) for one branch of sort.js and the strict equality operator (===) for the other.

Create a repository for testing as in the previous procedure, and push the following source code to the master branch.

// sort.js var number = [19, 3, 81, 1, 24, 21]; console.log(number);

2. Create branch

Create two branches.

$ git checkout -b add-sort-func2 $ git checkout -b add-sort-func1

3. Edit and push source code with add-sort-func1 branch

Edit the source code on the "add-sort-func1" branch.

// sort.js var sortNumber = function (number) { number.sort(function (a, b) { if (a == b) { return 0; } return a < b ? -1 : 1; }); }; var number = [19, 3, 81, 1, 24, 21]; sortNumber(number); console.log(number);

When the modification is completed, commit and push it.

$ git add sort.js $ git commit -m "<commit_message>" $ git push origin add-sort-func1

"A process of sorting an array has been added"

4. Make a pull request for the add-sort-func1 branch and merge

Make a pull request and merge.

5. Edit and push source code with add-sort-func2 branch

Switch the branch to "add-sort-func2".

$ git checkout add-sort-func2

Edit the source code.

// sort.js var sortNumber = function (number) { number.sort(function (a, b) { if (a === b) { return 0; } return a < b ? -1 : 1; }); }; var number = [19, 3, 81, 1, 24, 21]; sortNumber(number); console.log(number);

When the modification is completed, commit and push it.

$ git add sort.js $ git commit -m "<commit_message>" $ git push origin add-sort-func2

"A process of sorting an array has been added"

6. Create a pull request for add-sort-func2 branch

7. A conflict occurs.

Resolving conflicts

When a conflict occurs, you can merge branches manually. Let's merge the branch that you're working on and which is the target branch for the pull request to be pulled (in this case, master branch).

1. Pull master branch

$ git pull origin master

2. Resolve the conflict locally

// sort.js var sortNumber = function (number) { number.sort(function (a, b) { <<<<<<< HEAD if (a === b) { ======= if (a == b) { >>>>>>> 839396c5383737ec06b9c2a842bfccc28f3996ef return 0; } return a < b ? -1 : 1; }); }; var number = [19, 3, 81, 1, 24, 21]; sortNumber(number); console.log(number);

Above ======= is the local repository, and below is the remote repository. This time, keep the code of the local repository and delete the remote repository because the former will make a better code.

// sort.js var sortNumber = function (number) { number.sort(function (a, b) { if (a === b) { return 0; } return a < b ? -1 : 1; }); }; var number = [19, 3, 81, 1, 24, 21]; sortNumber(number); console.log(number);

3. Commit and push the modified source code again

$ git add sort.js $ git commit -m "<commit_message>" $ git push origin add-sort-func2 "Conflict resolved"

4. The conflict has been resolved.

There is no longer a conflict and you can now merge.