Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to git merge, but not using the latest commit

Tags:

git

git-merge

I have a master branch and a develop branch. The develop branch has moved ahead of the master by about 10 commits, but the version approved by the client included only the first 8 commits.

How do I merge only the first 8 commits from develop into master?

Normally I would do this:

git checkout master
git merge develop

But obviously that would merge in all of the develop commits.

like image 558
DatsunBing Avatar asked Oct 16 '18 05:10

DatsunBing


Video Answer


3 Answers

You may merge via SHA-1 commit hash, e.g.

git checkout master
git merge 3JH9sdx8

Where 3JH9sdx8 is the commit hash of develop from two commits prior to the HEAD of the branch. To find that 3JH9sdx8 hash, you could use git log develop and check.

like image 160
Tim Biegeleisen Avatar answered Oct 19 '22 20:10

Tim Biegeleisen


You can create a branch 2 version back

git checkout dev
git checkout -b devapproved @~2

Then you can merge that branch

git checkout master
git merge devapproved
like image 42
VonC Avatar answered Oct 19 '22 20:10

VonC


you could get the merge's version and create temporary branch ,for example:

# find the commit id
git log --oneline 

# checkout new branch by commit id 
git checkout commitID  -b tmp

# Switched to branch 'master'
git checkout master

git merge tmp

# delete branch
git branch -d tmp
like image 1
mango Avatar answered Oct 19 '22 19:10

mango