6

Possible Duplicate:
How to cherry pick a range of commits and merge into another branch

I want to cherry-pick 19 commits from one branch and apply them to another branch. All of the commits are sequential (commit 1, commit 2 ... commit 19), and the last commit is not the most recent commit (i.e. there are other commits that come after it whose changes I don't want to apply). How can I apply my changes to a branch without typing git cherry-pick for each commit?

Community
  • 1
  • 1
BJ Dela Cruz
  • 5,194
  • 13
  • 51
  • 84

2 Answers2

13

git cherry-pick $from_sha..$to_sha

Oleksandr Kravchuk
  • 5,963
  • 1
  • 20
  • 31
0

A way to do it manually (without cherry picking)


make a new branch from the head of your branch where the commits are located git branch newB

hard reset this new branch to the last commit git reset --hard <shaID of Commit19>


method 1

do a mixed reset to the commit directly before the first commit git reset --mixed <shaId of the mentioned commit>

do a stash on this 'modified' code to just have the commits 1 to 19 git stash

goto where you want to apply this manual cherry pick and do a pop git checkout <dstBranch> && git stash pop


method 2 (this method will keep the commit msgs)

do a hard reset to the commit right before the first commit git reset --hard <shaId of the mentioned commit>

do a squashed merge with the reflogs previous state git merge --squash HEAD@{1}

now you will see that commits 1 - 19 will be indexed and if you do a commit, the commit msg will be prepopulated with all of the individual commits msgs... allowing you to modify the msg as wanted

Now that you have your commit, cherry pick this one commit to where you want it. It has the benefit of having all of the wanted commit msgs.


when done delete the temp branch to get rid of all of the junk that you've done to do your internal pick git branch -D newB

g19fanatic
  • 10,567
  • 6
  • 33
  • 63