Git pull results in extraneous “Merge branch” messages in commit log

后端 未结 5 1619
傲寒
傲寒 2020-12-04 07:02

I\'m working with another developer on a project, and we\'re using Github as our remote repo. I\'m on a Mac using git 1.7.7.3, he\'s on Windows using git 1.7.6.

This

5条回答
  •  暖寄归人
    2020-12-04 07:55

    This answer has been revised, as my understanding, diagrams, and conclusions were incorrect.


    git pull causes merge commits because git is merging. This can be changed by setting your branches to use rebase instead of merge. Using rebase instead of merge on a pull provides a more linear history to the shared repository. On the other hand, merge commits show the parallel development efforts on the branch.

    For example, two people are working on the same branch. The branch starts as:

    ...->C1
    

    The first person finishes their work and pushes to the branch:

    ...->C1->C2
    

    The second person finishes their work and wants to push, but can't because they need to update. The local repository for the second person looks like:

    ...->C1->C3
    

    If the pull is set to merge, the second persons repository will look like.

    ...->C1->C3->M1
          \      /
           ->C2->
    

    Where M1 is a merge commit. This new branch history will be pushed to the repo. If instead, the pull is set to rebase the local repo would look like:

    ...->C1->C2->C3
    

    There is no merge commit. The history has been made more linear.

    Both choices reflect the history of the branch. git allows you to choose which history you prefer.

    There are indeed places where rebase can cause a problem with remote branches. This is not one of those cases. We prefer to use rebase as it simplifies an already complicated branch history as well as shows a version of the history relative to the shared repository.

    You can set branch.autosetuprebase=always to have git automatically establish your remote branches as rebase instead of master.

    git config --global branch.autosetuprebase always
    

    This setting causes git to automatically create a configuration setting for each remote branch:

    branch..rebase=true
    

    You can set this yourself for your remote branches that are already setup.

    git config branch..rebase true
    

    I would like to thank @LaurensHolst for questioning and pursuing my previous statements. I have certainly learned more about how git works with pull and merge commits.

    For more information about merge commits you can read Contributing to a Project in ProGit-Book. The Private Small Team section shows merge commits.

提交回复
热议问题