what does git merge origin/master do?

前端 未结 2 1467
眼角桃花
眼角桃花 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.

    0 讨论(0)
  • 2021-01-31 04:49

    What this does is merges the branch referred to as origin/master into your current branch. The order is very important. The word origin means the place from which you cloned your repository, i.e., the origin of the repository, the word master is just a branch name, however master is usually used as the main branch, or the trunk branch as some other systems call it.

    Merge might need to do a commit depending on the state of your development. If your history hasn't diverged from the origin, it can do what is called a fast-forward---all that needs to be done is put the new history on top of yours. If your development has diverged from the origin then if the merge can be done with no conflicts then the merge is done and a new commit is recorded at HEAD to specify the merge and the two parents.

    Furthermore, if merging can't be done because of a conflict, your working copy is updated to reflect the fact that there are conflicts, then when you fix them, you manually make the commit that records the merge.

    0 讨论(0)
提交回复
热议问题