简体   繁体   中英

Is there a difference between git merge origin/repo and git merge origin repo?

I use the later mainly just because it looks slightly more readable. I'm not sure if the command is equivalent, it seems to do a merge from the remote but most examples include the slash.

My merge workflow:

git fetch origin
git pull origin mybranch
git merge origin otherbranch

Is this correct?

git help merge doesn't mention the possibility to mention a remote as one of the arguments. It just says the un-dashed arguments are commits. So, origin is understood as the top of the default branch on origin , plus local branch otherbranch (you can merge several commits together).

I use the later mainly just because it looks slightly more readable

I'm surprised by this question simply because if you've been doing this, you should by now have been able to see that it isn't doing what you expect.

Your command is not interpreted as git merge <remote> <branch> ; that is not a recognized merge syntax. merge is not one of the commands that interacts with a remote.

Rather it is git merge <branch1> <branch2>

Here <branch1> is origin . Assuming you don't have a ref named origin but do have a remote configuration named origin , this will be interpreted as "the default branch of origin . Assuming you have a ref named remotes/origin/HEAD (you can look for what this is with git branch -a |grep HEAD or something like that), that's the default branch of origin .

So what you're doing is an octopus merge, incorporating

  • Either a ref named origin or, more likely, the default branch of the origin remote - which is likely origin/master , AND
  • A local ref named otherbranch

into the current branch (into which your previous pull command had merged origin/mybranch ).

The circumstances where that would look anything like merging the from the remote reef origin/otherbranch into the current branch are narrow and mostly trivial. The circumstances where it would generated an error and the merge would fail are numerous.

I don't mean any offense, but I sincerely believe that if you put so much value on tweaking the syntax to look "slightly more readable" to you, then the command line may not be the interface for you.

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