Information Technology Reference
In-Depth Information
<<<<<<< HEAD
two
=======
The second part of the conflict comes from the fr branch. The conflicting word is
deux . This information is shown as:
=======
deux
>>>>>>> fr
How do you resolve a conflict in git? This is done with a single command $ git
add . From now on you need to remember one simple rule: staging a file resolves a
conflict . In terms of states, we can say that staging a file changes its state from UU into
M_ . At first, it may be surprising that the content of a file doesn't matter. You can leave
the file as shown in Listing 9-5 and commit it with the <<<<<<<, =======,
>>>>>>> markers, if you wish. When you edit a file and remove these markers it
doesn't mean that you have resolved a conflict. This is done only when you stage a file
(with $ git add command, for example).
From time to time you would need to resolve the conflict by using the contents in-
troduced in one branch and ignoring the changes from the other branch. It will be espe-
cially important for binary files. You can achieve this with two commands:
$ git checkout --ours [filename]
$ git checkout --theirs [filename]
The --ours flag means the current branch. This is the en in the recipe. The --
theirs flag means the branch passed to the $ git merge command. In this recipe
it is the fr branch. In other words the command $ git checkout --ours
numbers.txt will produce in the working directory the file shown in Listing 9-2 ,
while the command $ git checkout --theirs numbers.txt —the file
shown in Listing 9-3 . Notice that these commands do not resolve conflicts. They only
restore the contents of the file without changing its state. The restored file remains in
UU state.
If you want to produce the file shown in Listing 9-5 you can use:
$ git checkout --merge [filename]
Search WWH ::




Custom Search