合并分支而不检出分支 [英] Merge branches without checking out branch

查看:62
本文介绍了合并分支而不检出分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个分支。

  master [实时服务器] 
\
阶段[Stage Server我们在哪里测试更改;合并提交]
\
Dev [本地机器]

我想下游的变化。这些分支中的每一个都设置为相互追踪。



通常,对于下游的更改,我这样做:

git checkout stage&& git merge master



然后我检查dev和我是否做同样的事情

git checkout dev&& git merge stage



然后全部推送它们:
git push origin --all $ b

有没有办法在没有检查到每个分支的情况下下载这些更改?

我可能会使用错误的术语。我不完全确定是否正确使用上游/下游术语。

解决方案

确实可以将分支B合并到分支A中,而不必检出分支A 如果是快进合并



您可以使用带有 fetch 的refspec来执行合并。如果使用 git merge 将分支B合并到分支A中会导致快进合并,那么您可以执行以下操作而不必检出A:

  git fetch< remote> B:A 



文件



以上匹配refspec格式

$ g $ fetch< remote> <信源>:其中目的地>

git fetch 的文档(重点是我的):


匹配< src> 的远程参考被获取,如果< ; dst> 不是空字符串,与之相匹配的本地ref使用 < src>



另请参阅




  1. Git结账和合并,而不接触工作树


  2. >合并,更新和拉动Git分支而不使用结账功能

  3. 合并而不更改工作目录

  4. 合并没有签出的分支



I have 3 branches.

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

I would like to downstream the changes to. Each of these branches are set to tracking each other.

Normally, to downstream the changes i do this:

git checkout stage && git merge master

Then i checkout dev and i do the same

git checkout dev && git merge stage

Then push them all: git push origin --all

Is there a way to downstream those changes without checking out into each branch?

I maybe using the wrong terminology. I'm not totally sure if i'm using upstream/downstream terminology correctly.

解决方案

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

这篇关于合并分支而不检出分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆