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.
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.
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.
question about Commit Id's
How to merge branch till specific commit id via REST API - Bitbucket Server - The Atlassian Developer Community
git - Get the commit id of merged Pull Requests - Stack Overflow
Adding commit ID to file during push or merge after pull request
A development team has two separate Merge Requests and when one was merged into the master branch the development team claimed that a second unrelated merge request also got merged at the exact same time. At first I assumed that this was a problem between the keyboard and chair, but after investigating a bit, I noticed that both Merge Requests (different branches) somehow had the same Commit ID. I'm like 99.99% sure that shouldn't happen (as in two branches/merge requests having the same commit id), and that should explain why they merged together, but I want to make sure I'm understanding the problem correctly. Can anyone confirm for me?
git cherry-pick should be your answer here.
Apply the change introduced by an existing commit.
Do not forget to read bdonlan's answer about the consequence of cherry-picking in this post:
"Pull all commits from a branch, push specified commits to another", where:
A-----B------C
\
\
D
becomes:
A-----B------C
\
\
D-----C'
The problem with this commit is that git considers commits to include all history before them
Where C' has a different
SHA-1ID.
Likewise, cherry picking a commit from one branch to another basically involves generating a patch, then applying it, thus losing history that way as well.
This changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this).
More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.
You can use git cherry-pick to apply a single commit by itself to your current branch.
Example: git cherry-pick d42c389f
I have two branches, main and develop. Lets say that this is my current commit history:
A - B - C - D (main) (tag 1.0.0) - E - F - G (tag 1.0.1) - H (develop)
I want to bring main to G (tag 1.0.1) so that it is one commit behind develop. Note that, I want all commits between main and G to also be included. Would I use cherry-pick or is there a better way?
Add this to your ~/.gitconfig:
[alias]
find-merge = "!sh -c 'commit=$0 && branch=${1:-HEAD} && (git rev-list $commit..$branch --ancestry-path | cat -n; git rev-list $commit..$branch --first-parent | cat -n) | sort -k2 -s | uniq -f1 -d | sort -n | tail -1 | cut -f2'"
show-merge = "!sh -c 'merge=$(git find-merge $0 $1) && [ -n \"$merge\" ] && git show $merge'"
Then you can use the aliases like this:
# current branch
git find-merge <SHA-1>
# specify master
git find-merge <SHA-1> master
To see the merge commit's message and other details, use git show-merge with the same arguments.
(Based on Gauthier's answer. Thanks to Rosen Matev and javabrett for correcting a problem with sort.)
Your example shows that the branch feature is still available.
In that case h is the last result of:
git log master ^feature --ancestry-path
If the branch feature is not available anymore, you can show the merge commits in the history line between c and master:
git log <SHA-1_for_c>..master --ancestry-path --merges
This will however also show all the merges that happened after h, and between e and g on feature.
Comparing the result of the following commands:
git rev-list <SHA-1_for_c>..master --ancestry-path
git rev-list <SHA-1_for_c>..master --first-parent
will give you the SHA-1 of h as the last row in common.
If you have it available, you can use comm -1 -2 on these results. If you are on msysgit, you can use the following perl code to compare:
perl -ne 'print if ($seen{$_} .= @ARGV) =~ /10$/' file1 file2
(perl code from http://www.cyberciti.biz/faq/command-to-display-lines-common-in-files/ , which took it from "someone at comp.unix.shell news group").
See process substitution if you want to make it a one-liner.