Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can git apply leave conflict markers inline like git rebase?

git rebase leaves the conflict markers inline in files; something like:

<<<<<<< HEAD
Whatever line + context is different from the previous commit
=======
Whatever line + context is different from the commit being applied
>>>>>>> new version, new branch:app/views/common/version.txt

When I use git apply to apply a patch created with git format-patch, it will fail to leave any files modified by default. I can give it --reject which will cause it to create .rej files for those that have unresolvable conflicts, but really, I want it to modify files and leave every in the state that git rebase does so I can just open the file, manually merge it, and then git add it and tell git apply to continue. Is there some way to do this that I just don't know of?

like image 571
kcstrom Avatar asked Mar 14 '12 14:03

kcstrom


People also ask

Can rebase have conflicts?

When you perform a git rebase operation, you're typically moving commits around. Because of this, you might get into a situation where a merge conflict is introduced. That means that two of your commits modified the same line in the same file, and Git doesn't know which change to apply.

What is << head in git?

The HEAD points out the last commit in the current checkout branch. It is like a pointer to any reference. The HEAD can be understood as the "current branch." When you switch branches with 'checkout,' the HEAD is transferred to the new branch.


1 Answers

For me the following works:

git init
seq 1 30 > file
git add file
git commit -m 1-30
sed -i '13a13.4' file
git commit -m 'add 13.4' file
git format-patch -1
git reset --hard HEAD^
sed -i 13d file
git commit -m 'remove 13' file
git am -3 0001-add-13.4.patch

After that file has conflict markers. That is use git am -3 instead of git apply.

like image 187
Uwe Kleine-König Avatar answered Oct 16 '22 20:10

Uwe Kleine-König