what does git merge origin/master do?

前端 未结 2 1472
眼角桃花
眼角桃花 2021-01-31 04:01

After fetching from remote using git fetch, we need to use something like

git merge origin/master

I would like to know if this com

2条回答
  •  暖寄归人
    2021-01-31 04:39

    git merge origin/master can do one of two things (or error).

    In the first case, it creates a new commit that has two parents: the current HEAD, and the commit pointed to by the ref origin/master (unless you're doing something funny, this is likely to be (the local pointer to) the branch named master on a remote named origin, though this is completely conventional).

    In the second case, where there is no tree-level merge necessary, rather than creating a new commit, it updates the currently checked-out ref to point to the same commit as is pointed to by origin/master. (This is called a fast-forward merge -- git can be directed to either always or never do this when you merge through command-line flags).

    It does not call git commit directly, which is a higher-level (porcelain in the git-parlance) command intended for users.

    Calling git merge master/original will try and resolve master/original to a commit, which will almost certainly (again, unless you've done something deliberate) not be the same as origin/master. If you happen to have a remote named master that has a branch named original, it will create a new commit which has that as the second parent.

    You may find git help rev-parse to be helpful in deciphering how git attempts to resolve ref names or other notations into commits.

提交回复
热议问题