Git:如何自动合并本地分支与远程跟踪而无需提取
想象一下,我有几个分支:master、a、b、c ...
现在我在 master 分支和“git pull”中。这会将所有更改从远程服务器获取到 origin/master、origin/a、origin/b ...分支,并将 CURRENT 分支(master)与 origin/master 合并。但随后我想切换到 A 分支,并再次合并来自远程跟踪分支的这些远程更改,而无需再次获取更改(因为它们已经位于 origin/a 分支中)。
是否有一些更简单的方法可以做到这一点,而不是精确指定我跟踪的远程分支(即自动)?
Imagine, I have several branches: master, a, b, c ...
Now I'm in master branch and "git pull". This fetches all changes from remote server into origin/master, origin/a, origin/b ... branches and merges CURRENT branch (master) with origin/master. But then I want to switch to A branch and again merge these remote changes from remote tracked branch, WITHOUT fetching changes again (as they already are in origin/a branch).
Is there some simplier way to do this not specifying exactly remote branch I track (i.e. automatically) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不相信有一个内置命令可以做到这一点。但是,您可以这样做:
我想我已经很好地涵盖了我的基础 - 如果处于分离的 HEAD 状态,或者当前分支没有跟踪分支,它会以失败状态退出。它默认为 origin,就像普通的 git 传输命令一样。 (如果您尝试在跟踪远程分支以外的其他内容的分支上使用它,就会发生奇怪的事情,即不是 refs/heads/* 形式,但这似乎不太可能。) 看起来不是这样实际上可以节省你很多时间,但你就在这里!
如果你想使用它,只需将它存储在某个地方并为其添加别名,或者将其命名为 git-something 并将其放入你的 PATH 中。
I don't believe there's a built-in command for this. However, you could do something like this:
I think I've covered my bases pretty well - it exits with failure status if in detached HEAD state, or if the current branch doesn't have a tracking branch. It defaults the to origin, as do the normal git transfer commands. (Something weird will happen if you try to use it on a branch which is tracking something other than a branch on the remote, i.e. not of the form refs/heads/*, but that seems pretty unlikely.) Doesn't seem like it'd actually save you much time, but there you are!
If you want to use it, just store it somewhere and alias to it, or name it git-something and put it in your PATH.
我认为您可以简单地签出您的本地分支并从原始/分支的本地副本进行合并。
像这样的东西:
I think you can simply checkout your local branch and merge from your local copy of the origin/a branch.
Something like:
git pull
只不过是git fetch
+git merge
。使用参数--rebase
你也可以让它变基而不合并,这样你就可以切换到另一个分支并合并/变基:或者:
因为它没有做任何其他事情,我什至已经停止了完全使用拉力。我只是定期
git fetch
,这样我就可以轻松跟踪其他存储库中的更改,然后在准备好时git merge/rebase
。git pull
is nothing more thangit fetch
+git merge
. With the parameter--rebase
you can also have it rebase and not merge so you can just switch to the other branch and merge/rebase:or:
Since it doesn't do anything else I even have stopped using pull at all. I just
git fetch
regularly so I can track the changes in other repositories easily and thengit merge/rebase
whenever I'm ready.这将依次检查所有跟踪分支,并合并到相应的远程分支中:
如果合并有冲突,则使用 git reset 进行倒回,您必须手动执行此操作。
未经测试。
您还可以将一个或多个模式传递给 git for-each-ref ,以将其限制为某个分支或一组特定分支。
This will check out all tracking branches in turn, and merge in their corresponding remote branches:
If a merge has conflicts, it is rewound with
git reset
and you will have to do it manually.Untested.
You can also pass one or more patterns to
git for-each-ref
to restrict it to a certain branch or a certain set of them.