合并分支而不检出分支 [英] Merge branches without checking out branch
问题描述
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>
。
另请参阅
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
这篇关于合并分支而不检出分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!