Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge up to a specific commit

I created a new branch named newbranch from the master branch in git. Now I have done some work and want to merge newbranch to master; however, I have made some extra changes to newbranch and I want to merge newbranch up to the fourth-from-the-last commit to master.

I used cherry-pick but it shows the message to use the right options:

git checkout master     git cherry-pick ^^^^HEAD newbranch 

Can I use git merge to do it instead?

git merge newbranch <commitid> 
like image 671
Dau Avatar asked Nov 22 '11 06:11

Dau


People also ask

What does it mean to merge a commit?

Merge commits are unique against other commits in the fact that they have two parent commits. When creating a merge commit Git will attempt to auto magically merge the separate histories for you. If Git encounters a piece of data that is changed in both histories it will be unable to automatically combine them.


1 Answers

Sure, being in master branch all you need to do is:

git merge <commit-id> 

where commit-id is hash of the last commit from newbranch that you want to get in your master branch.

You can find out more about any git command by doing git help <command>. It that case it's git help merge. And docs are saying that the last argument for merge command is <commit>..., so you can pass reference to any commit or even multiple commits. Though, I never did the latter myself.

like image 189
KL-7 Avatar answered Oct 05 '22 15:10

KL-7