2

I have following commits:

repo dev---(222)---v1.0(111)

repo orig---v2.0(333)---

How can I cherry pick diff (reversely) in repo A between commit 111 and 222, then commit result into repo B using git?

I have a software repo (dev) with changes (commit 222), but the changes are done on unrelated history to original software repo (orig).

I did the following (my development repo is "dev", original repo is "orig"):

  • added original repo as remote tracking to "dev" repo
  • checked out the "orig" repo commit "v1.0(111)"
  • committed the changes to "dev" repo

Now I have a reverse diff of my changes: git diff v1.0(111) (222)

I would like to cherry-pick those changes and rebase onto v2.0(333) in "orig" repo.

However I did read in "How to cherry pick a range of commits and merge into another branch", that "cherry-pick A..B" form, A should be older than B. If they're the wrong order the command will silently fail.

How is it possible using git?

klor
  • 1,237
  • 4
  • 12
  • 37

1 Answers1

2

First, the cherry-pick command would be

git checkout 333
git cherry-pick -n v1.0~...222
git commit -m "apply diff between 1.0 and 222"

You need to cherry-pick A...B between the parent of v1.0 (since A is excluded) and B.

Second, since you want only one commit applied to 333 as a result, use the -n option.

This flag applies the changes necessary to cherry-pick each named commit to your working tree and the index, without making any commit.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250