Merge branches without checking out branch

后端 未结 3 411
我寻月下人不归
我寻月下人不归 2021-01-31 15:47

I have 3 branches.

     master [ Live Server]
      \\
       stage [ Stage Server Where we test changes; merge commits ]
        \\ 
         Dev [ Local Machi         


        
相关标签:
3条回答
  • 2021-01-31 16:18

    Enter git-forward-merge:

    Without needing to checkout destination, git-forward-merge <source> <destination> merges source into destination branch.

    https://github.com/schuyler1d/git-forward-merge

    0 讨论(0)
  • 2021-01-31 16:32

    You can't merge into a branch in the general case without having it checked out. There's a good reason for this, however. You need the proper working tree in order to denote and resolve merge conflicts.

    0 讨论(0)
  • 2021-01-31 16:38

    You can indeed "merge" a branch B into branch A without having to check out branch A, but only if it's a fast-forward merge.

    You can use a refspec with fetch to do the "merge". If merging branch B into branch A using git merge would result in a fast-forward merge, then you can do the following without having to checkout A:

    git fetch <remote> B:A
    

    The Documentation

    The above matches the refspec format

    git fetch <remote> <source>:<destination>
    

    From the documentation for git fetch (emphasis mine):

    The remote ref that matches <src> is fetched, and if <dst> is not empty string, the local ref that matches it is fast-forwarded using <src>.

    See Also

    1. Git checkout and merge without touching working tree

    2. Merge, update, and pull Git branches without using checkouts

    3. Merging without changing the working directory

    4. Merging Branches Without Checkout

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