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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…