如何使用默认分支名而不是“master”创建Git存储库?
你可以使用Git 2.28 (Q3 2020):现有存储库中主分支的名称,以及新创建存储库中第一个分支使用的默认名称,都是可配置的,因此我们最终可以摆脱硬编码的“master”。
GitHub从2020年8月开始提醒:
On October 1, 2020, if you haven't changed the default branch for new repositories for your user, organization, or enterprise, it will automatically change from master to main.
You can opt out of this change at any time:
For users, on the https://github.com/settings/repositories page
For organization owners, on the https://github.com/organizations/YOUR-ORGANIZATION/settings/repository-defaults page
For enterprise administrators, on the https://github.com/enterprises/YOUR-ENTERPRISE/settings/member_privileges page
This change is one of many changes GitHub is making to support projects and maintainers that want to rename their default branch.
To learn more about the changes we're making, see github/renaming.
但回到Git本身:(2.28,2020年第三季度)
参见提交508fd8e (29 Jun 2020) Đoàn trn Công Danh (sgn)。
参见Johannes Schindelin (dscho)的commit 0068f21、commit a471214、commit 0cc1b47、commit 32ba12d、commit 6069ecc、commit f0a96e8、commit 4d04658(2020年6月24日)和commit 489947c(2020年6月23日)。
参见Don Goodman-Wilson (DEGoodmanWilson)的commit 8747ebb(2020年6月24日)。
(由Junio C Hamano - gitster -在commit 11cbda2中合并,2020年7月6日)
Init:允许为新存储库指定初始分支名称
署名:Johannes Schindelin
There is a growing number of projects and companies desiring to change the main branch name of their repositories (see e.g. Mislav Marohnić's tweet for background on this).
To change that branch name for new repositories, currently the only way to do that automatically is by copying all of Git's template directory, then hard-coding the desired default branch name into the .git/HEAD file, and then configuring init.templateDir to point to those copied template files.
To make this process much less cumbersome, let's introduce a new option: --initial-branch=<branch-name>.
git init --initial-branch=hello myLocalRepo
# or
git config --global init.defaultBranch hello
git init myLocalRepo
And:
Init:允许通过配置设置初始分支名称的默认值
帮助:Johannes Schindelin
资助人:德里克·斯托利
签名人:Don Goodman-Wilson
我们刚刚引入了命令行选项——initial-branch=<branch-name>,以允许使用不同于硬编码的初始分支初始化一个新的存储库。
为了允许用户更永久地覆盖初始分支名称(即不必为每次git init调用手动指定名称),让我们引入init. defaultbranch配置设置。
注意:commit 489947c,关于合并提交消息,已经在Git 2.29中恢复,参见“如何自定义Git的合并提交消息?”
init.defaultBranch设置保持不变。
这会影响子模块:
子模块:回退到遥控器的头丢失的遥控器..分支
资助人:菲利普·布莱恩
署名:Johannes Schindelin
When remote.<name>.branch is not configured, git submodule update currently falls back to using the branch name master.
A much better idea, however, is to use the remote HEAD: on all Git servers running reasonably recent Git versions, the symref HEAD points to the main branch.
Note: t7419 demonstrates that there might be use cases out there that expect git submodule update --remote to update submodules to the remote master branch even if the remote HEAD points to another branch.
Arguably, this patch makes the behavior more intuitive, but there is a slight possibility that this might cause regressions in obscure setups.
Even so, it should be okay to fix this behavior without anything like a longer transition period:
The git submodule update --remote command is not really common.
Current Git's behavior when running this command is outright confusing, unless the remote repository's current branch is master (in which case the proposed behavior matches the old behavior).
If a user encounters a regression due to the changed behavior, the fix is actually trivial: setting submodule.<name>.branch to master will reinstate the old behavior.
请注意,在Git 2.29 (Q4 2020)中,contrib/中的测试将根据最近对fmt-merge-msg的更改进行调整。
参见Emily Shaffer (nasamuffin)的commit b87528c (03 Aug 2020)。
(由Junio C Hamano—gitster—在commit 83b8250中合并,2020年8月10日)
恢复“subtree:调整测试更改”
署名:Emily Shaffer
这将还原提交508fd8e8baf3e18ee40b2cf0b8899188a8506d07。
在6e6029a8 (fmt-merge-msg:允许合并目的地再次被省略)中,我们得到了对'master'进行合并的行为,默认情况下,在合并消息的末尾不包括"into 'master'"。不再需要此测试修复。
另外:
使用Git 2.29 (Q4 2020),更新测试以删除单词“master”。
参见Johannes Schindelin (dscho)的commit f33f2d3, commit b6211b8(2020年9月26日)和commit 432f5e6, commit 5a0c32b, commit 659288c(2020年9月21日)。
(由Junio C Hamano - gitster -在commit 58138d3中合并,2020年10月5日)
测试:避免主分支名称的变化
署名:Johannes Schindelin
The term master has a loaded history that serves as a constant reminder of racial injustice. The Git project has no desire to perpetuate this and already started avoiding it.
The test suite uses variations of this name for branches other than the default one. Apart from t3200, where we just addressed this in the previous commit, those instances can be renamed in an automated manner because they do not require any changes outside of the test script, so let's do that.
Seeing as the touched branches have very little (if anything) to do with the default branch, we choose to use a completely separate naming scheme: topic_<number> (it cannot be topic-<number> because t5515 uses the test_oid machinery with the term, and that machinery uses shell variables internally, whose names cannot contain dashes).
This trick was performed by this (GNU) sed invocation:
$ sed -i 's/master\([a-z0-9]\)/topic_\1/g' t/t*.sh
并且,仍然使用Git 2.29:
参见Johannes Schindelin (dscho)的commit 538228e, commit a15ad5d(2020年10月8日)。
(由Junio C Hamano—gitster—在commit 62564ba中合并,2020年10月8日)
T1415:避免使用main作为ref name
署名:Johannes Schindelin
In preparation for a patch series that will change the fall-back for init.defaultBranch to main, let's not use main as ref name in this test script.
Otherwise, the git for-each-ref ... | grep main(man) which wants to catch those refs would also unexpectedly catch refs/heads/main.
Since the refs in question are worktree-local ones (i.e. each worktree has their own, just like HEAD), and since the test case already uses a secondary worktree called "second", let's use the name "first" for those refs instead.
While at it, adjust the test titles that talk about a "repo" when they meant a "worktree" instead.