是否可以为 Git 中的分支添加别名?
我正在考虑大规模使用 Git。 我希望通过调用 master
分支 trunk
来提高采用率并使事情变得更容易。
这可以并且将会给 SVN 用户带来一些安慰。 我知道我可以创建一个名为 trunk
的分支,但这似乎偏离了 Git 规范,可能会导致一些用户感到困惑。
我知道我也可以根据自己的喜好创建和删除标签,但是当我检查这些标签时,它告诉我这是一个非本地分支,这对我来说很好,但可能不是我想要做的。
我是一个完全的 Git 新手,但在发布和构建系统方面是一位经验丰富的专业人士。
我想要做的是能够调用主干线。我已经看到了别名命令的能力 - 这是否也适用于版本化对象的名称?
我知道 git-svn 的存在和其他工具,但分层存储库系统的开销让我感到害怕。
I am looking into using Git on a massive scale. I was hoping to increase adoption and make things easier by calling the master
branch trunk
.
This can and will give SVN users some feelings of comfort. I know I can create a branch called trunk
, but that seems to deviate from the Git norms and might cause some users to get confused.
I know that I can also create and delete tags to my heart's content but when I checkout those tags it tells me it is a non local branch which is just fine with me but probably not what I want to be doing.
I am a total Git newb but a seasoned professional at release and build systems.
What I want to do is to be able to call master trunk. I have seen the ability to alias commands – does this apply for the names of versioned objects as well?
I know git-svn
exists and other tools but the overhead of layered repository systems frightens me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以按照 Greg 的建议重命名 master 分支主干,也可以创建一个对 master 分支的符号引用的主干,以便 git 和 svn 用户都拥有他们习惯的“主”分支。
请注意,Trunk 不是一等公民。 如果您签出
trunk
并执行git status
,您实际上将位于master
上,但是您可以使用trunk
命令在所有使用分支名称的地方(日志、合并等)。You can rename the master branch trunk as Greg has suggested, or you can also create a trunk that is a symbolic reference to the master branch so that both git and svn users have the 'main' branch that they are used to.
Note that trunk isn't a first class citizen. If you checkout
trunk
and perform agit status
you will actually be onmaster
, however you can use thetrunk
command in all places that you use the branch name (log, merge, etc.).Git 中的“master”这个名字没有什么特别的,只是按照惯例(默认情况下)这么称呼的。 如果您愿意,您当然可以将其称为“trunk”:
这与 Subversion 非常相似,其中“trunk”这个名称也只是按惯例这么称呼。 您可以在 Subversion 中将主分支称为“master”。
There is nothing special about the name "master" in Git, it's just called that by convention (and by default). You can certainly call it "trunk" if you like:
This is very much like Subversion, where the name "trunk" is only called that by convention too. You could have called the main branch "master" in Subversion.
这是查尔斯·贝利的答案中所示技术的安全包装。
请注意,git 版本 2.7.0 - 2.8.2(含)中的一个错误导致“gitbranch”显示“alias -> alias”而不是分支别名的“alias ->branch”。 如果您受到该错误的影响,我建议您升级到 2.8.3 或更高版本。
上游功能请求:
https://www.mail-archive.com/[电子邮件受保护]/msg161274.html
This is a safety wrapper around the technique shown in Charles Bailey's answer.
Please note that a bug in git versions 2.7.0 - 2.8.2 (inclusive) caused "git branch" to display "alias -> alias" instead of "alias -> branch" for branch aliases. I recommend upgrading to 2.8.3 or later if you are affected by that bug.
Upstream feature request:
https://www.mail-archive.com/[email protected]/msg161274.html
Tes,使用 git symbolic-ref;:
但是“当前分支”(
gitbranch --show-current
)将是“不正确的”(仍会显示目标分支而不是别名分支):在 Git 2.39(2022 年第 4 季度)之前,在检查了指向另一个分支的符号引用“分支”后,“
git symbolic-ref HEAD
"(man) 报告底层分支,而不是用户作为参数给出 checkout 的符号引用。该命令学习了“
--no-recurse
”选项,仅在取消引用symbolic-ref
一次后停止。请参阅提交 b77e3bd(2022 年 10 月 7 日),作者:Junio C Hamano (
gitster
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 4a48c7d,2022 年 10 月 21 日)git symbolic-ref
现在包含在其 手册页:Tes, using
git symbolic-ref <alias-branch> <targetbranch>
:Hut the "current branch" (
git branch --show-current
) would be "incorrect" (would still show the target branch instead of your alias branch):Before Git 2.39 (Q4 2022), after checking out a "branch" that is a symbolic-ref that points at another branch, "
git symbolic-ref HEAD
"(man) reports the underlying branch, not the symbolic-ref the user gave checkout as argument.The command learned the "
--no-recurse
" option to stop after dereferencing asymbolic-ref
only once.See commit b77e3bd (07 Oct 2022) by Junio C Hamano (
gitster
).(Merged by Junio C Hamano --
gitster
-- in commit 4a48c7d, 21 Oct 2022)git symbolic-ref
now includes in its man page: