Merging 2 branches together in GIT

后端 未结 3 1069
心在旅途
心在旅途 2020-12-12 09:52

I\'ve only just started to use GIT and think its wonderful, however I\'m a little confused over what the merge command does.

Let us say we have a workin

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 10:32

    merge is used to bring two (or more) branches together.

    a little example:

    # on branch A:
    # create new branch B
    $ git checkout -b B
    # hack hack
    $ git commit -am "commit on branch B"
    
    # create new branch C from A
    $ git checkout -b C A
    # hack hack
    $ git commit -am "commit on branch C"
    
    # go back to branch A
    $ git checkout A
    # hack hack
    $ git commit -am "commit on branch A"
    

    so now there are three separate branches (namely A B and C) with different heads

    to get the changes from B and C back to A, checkout A (already done in this example) and then use the merge command:

    # create an octopus merge
    $ git merge B C
    

    your history will then look something like this:

    …-o-o-x-------A
          |\     /|
          | B---/ |
           \     /
            C---/
    

    if you want to merge across repository/computer borders, have a look at git pull command, e.g. from the pc with branch A (this example will create two new commits):

    # pull branch B
    $ git pull ssh://host/… B
    # pull branch C
    $ git pull ssh://host/… C
    

提交回复
热议问题