9

I want to merge not the HEAD of my develop into the master branch but say five commits before theHEAD. How can I achieve this?

2 Answers 2

9

git merge actually works directly with commit IDs, so:

$ git merge a12399c 

will attempt to merge that commit (and its history) with your current branch.

You can spell a commit ID with a branch name:

$ git merge develop 

and the branch name resolves to the tip commit of the branch. This is what you are used to doing (and it is "better", in some sense, since the default merge commit message becomes "merge branch develop" rather than "merge commit a12399c"). But you can use a raw ID, or any other spelling for an ID, such as:

$ git merge develop~5 

which uses gitrevisions syntax to name the commit to merge.

(If you're not doing the merge yourself, but rather sending pull requests, you do need a name, because you don't do the merge. Instead, you send a request to someone else, asking them to do the merge for you—and to do that, you tell them "use this name I have set, that points to the commit ID I would like you to merge." The main complication here is that the name must be visible to the other person. The easiest way to deal with all of this is to set up a branch name, since branch names are visible to other people.)

Sign up to request clarification or add additional context in comments.

Comments

3

go to your tree and choose what point would you like to merge.

get the hash of the commit and then go to your terminal and checkout to your hash

After this, create a branch to this point, push and then open PR and merge =D

commands:

git checkout HASH_CODE git branch NEW_MERGE_BRANCH git push origin NEW_MERGE_BRANCH 

open PR, and merge or

git checkout master git merge --no-ff NEW_MERGE_BRANCH 

solution 2

git reset --soft HEAD@{5} git branch NEW_MERGE_BRANCH git push origin NEW_MERGE_BRANCH git checkout master git merge --no-ff NEW_MERGE_BRANCH 

2 Comments

Cool! What's PR tho?
pool request, take a look at github page has a submenu called poll request

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.