简体   繁体   中英

difference from: git merge branch vs git merge branch master

Assuming I am in the master branch, and I want to merge a branch called 'branch-A'.

There are any difference between calling or not the master branch?. ie doing like this

$ git merge branch-A

or like this:

$ git merge branch-A master

And if I invert the order???

$ git merge master branch-A 

If there are any it should be something simple I think. I don't see differences, but maybe there are something that I just can't see. Thanks

git merge branch-A will merge all changes made in branch-A to your current branch (master)

git merge branch-A master will merge all changes made in branch-A and master to you current branch. since you already are on master it should only merge branch-A

git merge master branch-A is the same. merge both branches to current branch, but in different order.

in other words: git merge ABCD will merge the branches A, B, C and D to your current checked out branch (eg master). the order you pass the branches as arguments is the order they are merged. this could be useful in case of conflict-handling. the target of merge is always the branch you have checked out before.

Merging more than two branches is called Octopus merge

Ordinarily, you wouldn't want to merge the branch you are currently on. So, I don't think you should be trying to merge the master branch into itself.

The first case will merge the branch-A to the current (master) branch.

For the second and third cases, when two or more branches are provided to the git merge command, they are merged into the current branch in the order the are supplied.

For Example:

git merge branch-A branch-B

This will merge branch-A into the current branch and then branch-B

This answer explains more about Octopus merge Git octopus merge order of multiple branches

You will also find this documentation helpful: https://git-scm.com/docs/git-merge

If you are on master and you want to merge branch-A into master the most straight-forward way to accomplish that is:

# first make sure you are on master
# (be on the branch you want to merge INTO)
git checkout master

# merge the other branch into master
git merge branch-A

From the doc :

Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM