Whats a good method to cherrypick all missing commits by an author in one branch to another

StackOverflow https://stackoverflow.com/questions/23570382

  •  19-07-2023
  •  | 
  •  

Question

Say I have made a bunch of changes in master. But, I want to cherrypick all the ones not in branch:release-5 onto to it.

Était-ce utile?

La solution

You can cherry pick, but it would be much easier if you rebase:

git checkout -b missing-commits master
git rebase -i --author=me release-5

All the commits already in release-5 won't be picked, and only your commits will. Afterwards you can merge the branch missing-commits into release-5.

That being said you can use cherry-pick:

git cherry-pick --skip-empty --cherry-pick --no-merges --right-only --topo-order --do-walk master...release-5

As you can see it's much easier to use git rebase, which interally does the cherry-picking for you.

Autres conseils

The whole point of cherry-picking is that you can select a specific subset of commits you want to copy over to your branch. It exists explicitely because there are situations in which you don’t want to integrate all commits from another branch using merging.

Now, if you find yourself in a situation where you want to cherry-pick all commits that are on some other branch, then you’re exactly in the merging situation where you just want to merge that branch into your current branch to integrate all changes:

git checkout release-5
git merge master

That being said, the A..B revision range syntax allows you to specify commits that are reachable from B without those reachable from A. So in your case, you would want to use release-5..master to select all commits that are on master but not reachable from your release-5 branch:

git cherry-pick release-5..master

But again, if you just want all those, merging is absolutely the better option because it won’t duplicate the commits and keep an actual history available.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top