I\'m trying to merge a pull request that has one conflict in one file (see below). The instructions for merging the pull request are provided by github are as follows. Its i
There's no way around resolving conflicts, that's how revision control works (if Alice says "a" and Bob says "b", how should Git know which one is correct unless you tell it?). All you can do is direct git
to resolve them itself when merging in one of several possible ways, e.g.
git merge -s recursive -X theirs <branch>
(-s recursive
is the default when there's only one <branch>
so you can omit it here)
Now that you already have a conflict in your tree, you either
git add
it (add
in Git doubles as marking a file resolved)git commit
to complete the merge; orgit merge --abort
and retry the merge with the above-mentioned auto-resolution optionsResolving a conflict is just like dealing with any other work in progress. All changes must be staged (git add
) and then committed. Files which have successfully auto merged are already staged. Conflicted files are not.
Edit the conflicted files to your satisfaction, stage them (git add
), and when that is all done, git commit
.
In your case specifically...
test.cpp
to fix the conflicts (they have <<<<
markers)git add test.cpp
git commit
Push development into master
git push --force origin branchA:branchB
This will force a merge and then push
If you know the changes in the current working branch is what you want, you can simply add ours
flag to a git merge.
git merge -s ours master
This effectively ignores all other branch changes and guarantees the merge output is that of the current working branch.
More info and strategies here : https://www.atlassian.com/git/tutorials/using-branches/merge-strategy
There's no way to merge without resolving conflicts. Otherwise, how would git know what to merge? You can, however, checkout the version from either branch you're merging using git checkout --ours <filepath>
or git checkout --theirs <filepath>
. Here's an example:
Suppose you're on the master branch merging in staging:
git checkout master
git merge staging
And git shows a bunch of conflicts:
...
CONFLICT: Readme.md
...
If you want to keep the version of Readme.md
that's on master, then you would run:
git checkout --ours Readme.md
Note that since you're on master --ours
refers to "this" branch, i.e. master.
Now, you can simply add it to the index to mark it as resolved:
git add Readme.md
This effectively ignores any changes to Readme.md
on the staging
branch.
You can repeat this process for each file you want to omit from the merge. When you're done, commit as you normally would:
git commit -m "whatever..."
In order to repeat it for all files with conflicts you can do
for f in $(git diff --name-only --diff-filter=U | cat); do
echo "Resolve conflict in $f ..."
git checkout --theirs $f
done