有没有一种方法来设置主机Git存储库,这样从它的(本地)克隆进行的任何Git拉取默认使用——rebase ?通过在Stack Overflow上搜索,我了解了分支。Autosetuprebase,但它需要每个克隆单独配置。

我的项目流程是这样设置的,我们在将一个特征分支合并到它之前拉开发分支。这个pull几乎总是使用。rebase,我试着弄清楚这是否可以是默认值。


当前回答

这使得——rebase选项成为对给定分支执行git pull时的默认选项。

@Flimm,我需要添加真,使你的第一个选择工作。

所以正确的语法是:

git config branch.<branch>.rebase true

在develop分支上运行此命令:

git config branch.develop.rebase true

现在.git/config中的开发部分看起来像这样:

[branch "develop"]
        remote = origin
        merge = refs/heads/develop
        rebase = true

其他回答

如果你正在使用.gitconfig,并且想要在拉取时使用merge而不是rebase,你可以将这段代码插入到你的.gitconfig中:

[pull]
  rebase = false

这将消除在您设置的每个新项目上烦人的警告。

缺省的拉行为现在有3个不同级别的配置。从最一般的到最细的,它们是:

1. pull.rebase

将此设置为true意味着git pull总是等价于git pull——rebase(除非branch.<branchname>。Rebase显式设置为false)。这也可以为每个存储库或全局设置。

2. branch.autosetuprebase

将此设置为总是意味着每当创建跟踪分支时,将为其创建如下所示的配置条目。对于更细粒度的控制,也可以将其设置为never、local或remote,并且可以为每个存储库设置或全局设置。详见git config——help。

3.分支。< branchname > .rebase

将此设置为true意味着该特定分支将始终通过rebase从其上游进行拉取,除非显式地使用git pull——no-rebase。

结论

因此,虽然您不能更改存储库的所有未来克隆的默认行为,但您可以通过git config -global pull更改当前用户(现有和未来)存储库的默认行为。变基真的。

目前没有办法为存储库设置默认策略。

如果你想自己使用它,并且至少使用git 1.7.9,你可以全局设置pull。调整配置如下:

git config --global pull.rebase true

但是你必须在每台机器上做。一个选项是使用该选项配置默认用户主页模板/框架。不过,用户可能会改变这个选项。

如果您不想要合并,您可以定义一个服务器端钩子来拒绝带有合并的推送。

供您参考,他是pull.rebase的源文档:

When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run. See "branch..rebase" for setting this on a per-branch basis. When merges, pass the --rebase-merges option to git rebase so that the local merge commits are included in the rebase (see git-rebase for details). When preserve, also pass --preserve-merges along to git rebase so that locally committed merge commits will not be flattened by running git pull. When the value is interactive, the rebase is run in interactive mode. NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git-rebase for details).

如何

git config --global pull.rebase true

这将告诉git总是拉与rebase。

这使得——rebase选项成为对给定分支执行git pull时的默认选项。

@Flimm,我需要添加真,使你的第一个选择工作。

所以正确的语法是:

git config branch.<branch>.rebase true

在develop分支上运行此命令:

git config branch.develop.rebase true

现在.git/config中的开发部分看起来像这样:

[branch "develop"]
        remote = origin
        merge = refs/heads/develop
        rebase = true