I created a new branch from my master branch. In my new branch, I have a a few commits (A-B-C-D-E). I want to merge commits C and everything before that into master. I know I can use cherrypick A, C and C. But is there a way to tell git to include C and everything before that and merge into master?
1 Answers
Just run git merge hash-of-desired-commit
.
In fact, this is how git merge
actually works. Git does not merge based on branches,1 but rather based on commits. When you run git merge branch-name
, Git turns the name into a commit hash, and then does the merge with the hash. The only thing that the name does is set the default commit message (to, e.g., merge branch br
or merge branch br into feature
).
1To be more precise, what I mean here is branch names. See also What exactly do we mean by "branch"? When you specify a commit hash, the resulting merge contains a subset of the commit graph, and the word branch also means some subset of a commit graph, so in that sense, Git does merge "branches".
The problem here is that the word branch itself is overused, which drains it of meaning. Have you ever been to a party where everyone is named Bruce? "Hey, Bruce! Bruce told me to tell you that Bruce called Bruce to relay that Bruce wasn't going to be able to make it. Please tell this to Bruce, OK?" (Which Bruce is actually not going to make it?)

- 448,244
- 59
- 642
- 775