Merge up to a specific commit
Solution 1
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.
Solution 2
To keep the branching clean, you could do this:
git checkout newbranch
git branch newbranch2
git reset --hard <commit Id> # the commit at which you want to merge
git checkout master
git merge newbranch
git checkout newbranch2
This way, newbranch will end where it was merged into master, and you continue working on newbranch2.
Solution 3
Run below command into the current branch folder to merge from this <commit-id>
to current branch, --no-commit
do not make a new commit automatically
git merge --no-commit <commit-id>
git merge --continue
can only be run after the merge has resulted in conflicts.
git merge --abort
Abort the current conflict resolution process, and try to reconstruct the pre-merge state.
Dau
Updated on July 08, 2022Comments
-
Dau almost 2 years
I created a new branch named
newbranch
from themaster
branch in git. Now I have done some work and want to mergenewbranch
tomaster
; however, I have made some extra changes tonewbranch
and I want to mergenewbranch
up to the fourth-from-the-last commit tomaster
.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>