[英]git: how do I configure tracking a branch by merging and not by rebasing?
I want to setup a local tracking branch that will be tracking a remote branch by merge and not by rebase. 我想设置一个本地跟踪分支,它将通过合并而不是通过变基来跟踪一个远程分支。
When I do git pull
I want to merge from the remote branch, not to rebase. 当我执行
git pull
我想从远程分支合并,而不是重新设置基准。
When I do: 当我做:
git checkout -b someBranch origin/someBranch
and then 接着
git remote show origin
I see: 我懂了:
Local branches configured for 'git pull':
someBranch rebases onto remote someBranch
Local refs configured for 'git push':
someBranch pushes to someBranch (local out of date)
The same thing also happens if I do 如果我做同样的事情
git checkout --track origin/someBranch
Is this somehow configured locally? 是否以某种方式在本地配置?
How do I change this behaviour? 我该如何改变这种行为?
By default, GIT does merge
during pulls. 默认情况下,GIT会在拉取过程中
merge
。 If yours is doing rebase, then it seems that at some point of time you had changed that behavior. 如果您正在重新设置基准,那么似乎您已在某些时候更改了该行为。 Or someone helpful did that for you.
或有人帮助您。
Citing after this article (1) and this article (2) and this article (3) - which all describe how to do the opposite thing: 引用本文(1) , 本文(2)和本文(3) -都描述了如何做相反的事情:
(from 1) There is a configuration flag in GIT that, when enabled, changed the default behavior of pull
from merge
to rebase
. (从1开始)GIT中有一个配置标志,启用该标志后,将
pull
的默认行为从merge
更改为rebase
。 Check if you have it set: 检查是否已设置:
# git >= 1.7.9:
git config --global pull.rebase
git config pull.rebase
In newer GIT clients, it works intuitively. 在较新的GIT客户端中,它可以直观地工作。 It is enabled if it's
true
. 如果为
true
,则启用它。 Just turn the flag off. 只需关闭标志。
In older however, it works differently. 但是,在较旧的版本中,它的工作方式有所不同。
# git < 1.7.9:
git config --global branch.autosetuprebase
git config branch.autosetuprebase
# and also
git config branch.<name>.rebase
When autosetuprebase
is set to always
, git automatically sets rebase
flag on each new branch. 当
autosetuprebase
设置为always
,git会在每个新分支上自动设置rebase
标志。 This means that only you will probably want to not only disable autosetuprebase
, but also to turn off the already-set rebase
flag for each branch. 这意味着不仅您可能不仅要禁用
autosetuprebase
,而且还要关闭每个分支已设置的rebase
标志。
(from #2) (来自#2)
If you want another way (ie you've got old GIT client and tons of branches and you actually do mind writing a script that resets the flags) then another option is to create an alias for git pull
that will add --no-rebase
option, what will force it to do a merge. 如果您想要另一种方式(例如,您拥有旧的GIT客户端和大量分支,并且您确实想编写一个重置标志的脚本),那么另一种选择是为
git pull
创建一个别名,该别名将添加--no-rebase
选项,将迫使它执行合并。
(from #3) (来自#3)
This article says that the per-branch rebase
flag is kept in a config file. 本文说,每个分支的
rebase
标志保存在配置文件中。 So, after turning autosetuprebase
off, it seems you can quickly disable rebaseing on all or some branches by remove all rebase
lines from that config file. 所以,把后
autosetuprebase
过,看来你可以快速禁止rebaseing所有或删除一些树枝都rebase
从配置文件行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.