A
A
Alexandroppolus2022-01-20 17:54:41
git
Alexandroppolus, 2022-01-20 17:54:41

How to resolve the conflict from the command line?

Essence:

git checkout branch_a
git merge branch_b


now I have such crap in my x.js file
<<<<<<< HEAD
text1
=======
text2
>>>>>>> branch_b


and I know for sure that for this file I just need to select an option, for example, from branch_b (i.e. delete text1 and leave text2)

manually open the file and fiddle with the corners too lazy, is it possible with some kind of console command?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Kuznetsov, 2022-01-20
@Alexandroppolus

#отменить неудачное слияние
git merge --abort
# повторить слияние используя опцию theirs
git merge -Xtheirs branch_b 
# при конфликтах выберется вариант из вливаемой ветки

But it is not exactly. I always confuse ours and theirs )) I advise you to read in our book about types of merging
By default, when Git notices a conflict when merging branches, it adds conflict markers to the code, marks the file as conflicting, and lets you resolve it. If, instead of manually resolving the conflict, you want Git to simply use one particular version of the file and ignore the other, you can pass one of two options to the merge command, -Xoursor -Xtheirs.
In this case, Git will not add conflict markers. It will merge all non-conflicting changes, and for conflicting changes, it will take the entire version that you specified (this also applies to binary files).

too lazy to fiddle with corners

Everyone is lazy. Therefore, they use merge tools that help to deal with the "corners" in one click.
conflict-solver--base-changes-03906ff6.png
Or just select one option in the entire file and resolve conflicts in favor of one side.
resolve-dialog.png
If you want to do it from the command line, then it's done like this.
git checkout branch_b -- имя_файла # оставить версию файла из ветки branch_b
git add имя_файла # сбросить состояние конфликта
# ... разрешить другие конфликты
git merge --continue --no-edit # создать коммит слияния

Z
Zhbert, 2022-01-20
@Zhbert

Well, you can set sed on these “corners”, for example. But this is the wrong way, conflicts must be resolved with the mind and hands IMHO, otherwise it will come back to haunt you most likely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question