best way to resolve merge conflicts code example
Example 1: git find merge conflicts
git diff --name-only --diff-filter=U
Example 2: how to resolve conflict in git
This is very question because I am facing
with this issue all the time. Basically
conflict arises when more than one commit
that has to be merged with some change in the
same place or same line of code. In this case
git will not be able to predict which change
to take. So my approach to fix this issue,
I would stash my project to temporary memory
and pull the project from github to working
directory. I would fix the confict and
merge the project and than I would add,
commit and push it the updated version.
git stash -- > take my project to temp memory
git pull -- > pull the project from GitHub to working directory
(my computer)
git stash pop -- > take my project to my working directory,
fix the conflict and merge the project.
git add .
git commit –m “comment”
git push
Example 3: Automatic merge failed; fix conflicts and then commit the result.
cd REPOSITORY-NAME
git status
>
>
>
>
>
>
>
>
>
> no changes added to commit (use "git add" and/or "git commit -a")
If you have questions, please
<<<<<<< HEAD
open an issue
=======
ask your question in IRC.
>>>>>>> branch-a
If you have questions, please open an issue or
ask in our IRC channel if it's more urgent.
git add .
git commit -m "Resolved merge conflict by incorporating both suggestions."
Example 4: how to handle merge conflicts
git stash -- > take my project to temp memory
git pull -- > pull the project from GitHub to working directory
(my computer)
git stash pop -- > take my project to my working directory,
fix the conflict and merge the project.
git add .
git commit –m “comment”
git push