Home > Enterprise >  Apply diff, using a given strategy
Apply diff, using a given strategy

Time:09-06

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

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 or 6.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

git: patch does not apply

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.

  • Related