![](/img/trans.png)
[英]How to create copy of a snapshot (commit) in a branch onto another branch in git?
[英]How to create a Git Branch with an empty commit on it?
我对我的团队有一个非常具体的自定义要求,每次他们从main
分支创建一个 git 分支时,他们都被迫在其上创建一个带有消息的空提交,他们必须填写该消息。
我在 Google 上查看和搜索,但没有发现 Git 支持开箱即用的任何内容,AFAIK。 有没有办法通过一些自定义操作来做到这一点?
这是我通过图表询问的内容:
[a]-->[b]-->[c]-->[d]-->[e] *main-branch*
\
[empty-commit with message prompt to fill-in]--> *custom-branch*
从您的评论来看,您并不是在寻找一种强制开发人员这样做的方法,而是为了方便他们这样做。 为此,我建议使用别名。 例如,如果您让他们创建一个new-branch
别名,如下所示:
git config alias.new-branch '!f() { echo git checkout -b ${1}; git commit --allow-empty -m "${2}"; }; f'
然后他们可以使用以下命令在该分支上创建一个新分支和单个空提交:
git new-branch some-new-branch "here is the comment of the empty commit"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.