Most of the time we may face merge conflicts when we are sending PR requests. Reason is that we work on a different branch and commits our changes to that branch. At that time, other contributors may commit to the master branch.
In git, merging happens based on the time stamp you have made the commits. Consider following commit scenarios in master branch and test branch. These are the time stamps with commit ids.
20/06/2015 02.30pm – commit b004
Now when merging to the master branch, it goes to the commit b001 and starts merging based on the time stamp. So when this happens there can be merge conflicts.
Although you have already pushed your commits to the remote repo, you can do following to solve the merge conflicts in Pull request.
1. Get last commit id
commit id is shown in the red rectangle.
2. Reset the branch to the last commit in master branch
git reset commit_id
eg : git reset fb4dcc39c1c82e04b5f73a33103e47800cad2869
This command will not remove your changes in the branch. Once you use this command it will list down all the modified files.
3. Now commit your changes
git commit -m “Adding changes”
or use single line as below.
git commit -a -m “Adding changes”
4. Push your changes to the remote branch (test is the branch name)
git push origin test -f
-f is to force the changes you are making. Without -f it will not work. This will revert already committed changes in a remote branch.