Scott Tomaszewski
Scott Tomaszewski

Reputation: 1019

How to auto-resolve (--theirs) conflicts after applying a git patch --3way

Within a CI pipeline, I need to mirror changes over from another repo using patch files for every commit (dont ask). Im making the patches with

git format-patch -n HEAD^ --stdout > ../last_commit.patch

and then applying them with

git apply --3way ../last_commit.patch

which can lead to conflicts. Is there a way to automatically resolve these conflicts with something like --theirs (the repo that made the patch file)?

Is something like this safe enough, or am I asking for trouble?

git diff --name-only --diff-filter=U | xargs git checkout --theirs

Is there a better way to do this?

(Context: The repo with CI is generating a ton of code that gets persisted in two other repos. Reason for two repos is to temporarily support a legacy variant of the generated code and is deprecated, but we need to keep it around a bit longer. Im persisting the newly generated code in one repo, creating a patch, then applying the patch to the second repo. Nobody should be committing directly to the destination repos, so i'm not super concerned about auto-resolving the conflicts.)

Upvotes: 0

Views: 75

Answers (0)

Related Questions