Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git - merge from specific commit onwards

Tags:

git

Say i have a master and a develop branch - develop has a lot of commits that master does not for simplicity sake:

Develop:

Commit 1
Commit 2
Commit 3
Commit 4
Commit 5
Commit 6

I want to cut a new feature branch from master that does not have any of these commits in develop.

but the tricky part is that I want to merge develop into my feature from commit 3 onwards.

I could cherry pick but in reality there are many, many more commits than my simple example.

How can this be done?

like image 904
Marty Wallace Avatar asked May 26 '26 00:05

Marty Wallace


1 Answers

You could cherry-pick:

git checkout -b newfeature master
git cherry-pick commit2..develop

if that syntax isn't supported directly, there, use:

git cherry-pick $(git rev-list commit2..develop)

note: the first commit in the a..b range notation is not included in the list of revisions, thanks Carl

Otherwise, it looks like a case for rebase --root ... --onto. I always look up the specifics in the man page.

like image 138
sehe Avatar answered May 27 '26 13:05

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!