Resolve a pull request conflict
Let’s merge the branch that we’re working on and the target branch for the pull request to be pulled (in this case, the main branch).
First, pull the main branch.
$ git pull origin main
Next, resolve the conflict locally.
// sort.js
var sortNumber = function (number) {
number.sort(function (a, b) {
<<<<<<< HEAD
if (a === b) {
=======
if (a == b) {
>>>>>>> add-sort-func2
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 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);
Next, commit and push the modified source code again.
$ git add sort.js
$ git commit -m ""
$ git push origin add-sort-func2
"Conflict resolved"
The conflict has been resolved! You can now merge.