在 Git 中创建新分支时可以添加消息/注释/评论吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11886132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I add a message/note/comment when creating a new branch in Git?
提问by doub1eHyman
I'm doing some exploratory work where I will most likely be spending 30 min on several different variations of the same task. I want to track them in git so I can jump back and forth between approaches. And if there are 3 or 6 or 9 branches, I might need some more info than the branch name to tell them apart.
我正在做一些探索性工作,我很可能会在同一任务的几个不同变体上花费 30 分钟。我想在 git 中跟踪它们,以便我可以在方法之间来回跳转。如果有 3、6 或 9 个分支,我可能需要比分支名称更多的信息来区分它们。
What is the cleanest way to attach a comment to a new branch?
将评论附加到新分支的最简洁方法是什么?
回答by Christopher
You want branch descriptions:
你想要分支描述:
git branch --edit-description
This will open up your editor and let you attach metadata to the branch. You can extract it with:
这将打开您的编辑器并让您将元数据附加到分支。您可以使用以下方法提取它:
git config branch.<branch>.description
A couple of important notes:
几个重要的注意事项:
This is stored locally. By definition it can't be pushed since it's stored in
.git/config
. All the same it works great for this use case.If you delete the branch, the description will delete as well.
You can push this description into merge commits if you set
git config --global branchdesc true
. This means when you issuegit merge --log <branch>
, it'll force the branch description into the stock merge commit message. This has a lot of uses. For example, this is how I track topic branch release notes at my employer.
这是本地存储的。根据定义,它不能被推送,因为它存储在
.git/config
. 尽管如此,它对这个用例非常有用。如果删除分支,描述也将删除。
如果你设置了,你可以将此描述推送到合并提交中
git config --global branchdesc true
。这意味着当您发出 时git merge --log <branch>
,它将强制分支描述进入股票合并提交消息。这有很多用途。例如,这就是我在雇主处跟踪主题分支发布说明的方式。