Question
I have:
- A Git Repository
- A Patch (
.diff
) with several conflicts
I would like to apply the patch using a strategy (like theirs
), similar to git merge -s
. Can this be achieved using git
and/or patch
?
Related
- Resolve Git merge conflicts in favor of their changes during a pull
- How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?
CodePudding user response:
The patches listed on that page somehow mention what commit they should be applied on :
- three of them mention they apply to version
6.2
,6.1
or6.0
, - the other ones mention a commit hash in their name.
So, to apply the suggestion "create a branch and merge" (suggested by @eftshift0 or @Ôrel) :
git checkout -b with-patch <target commit: tag or has>
git apply <patch>
git commit
then switch back to your own branch, and use either merge
or cherry-pick
:
git checkout my-branch
git merge with-patch
# or
git cherry-pick with-patch
CodePudding user response:
While the git apply
command doesn't support --strategy
, it does support --reject
, which causes Git to generate *.rej
files, which utilities like wiggle can apply.
Example
$ git apply patch.diff
Hunk #1 applied cleanly
Hunk #2 rejected
See also
CodePudding user response:
Find the base revision for the patch and apply it there. There should be no conflicts, right?
git checkout -b temp the-base-revision
git apply the-diff-file
git commit-m 'the patch' -a
Then feel free to cherry-pifk, which should give you access to tbe options you are looking for.
git checkout blahblah # where I really wamt to apply it
git cherry-pick --someOption tenp
That should work.