Git中是否有一种为分支提供“描述”的方法?

虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。


当前回答

你可以使用

git config --get-regexp "branch.*.description"

其他回答

只使用:

git config branch.<branch name>.description

在该表扬的地方表扬: https://glebbahmutov.com/blog/git-branches-with-descriptions/

你可以使用

git config --get-regexp "branch.*.description"

Chris J建议的README可以工作,只要它使用.gitattribute中定义的自定义合并驱动程序进行设置。 这样,在合并期间始终保留README的本地版本。

分支的“描述”也被称为与元数据相关联的“注释”,它是不受支持的。

至少,对于一个README文件,你可以对任何分支执行:

$ git show myBranch:README

如果你的README在你的REPO的根目录,它将从任何路径工作,因为git show使用的路径是绝对的一个从REPO的顶部目录。

Git 1.7.9支持这一点。从1.7.9版本说明中可以看到:

 * "git branch --edit-description" can be used to add descriptive text
   to explain what a topic branch is about.

你可以在提交6f9a332、739453a3、b7200e8时看到该特性早在2011年9月就已经引入:

struct branch_desc_cb {
  const char *config_name;
  const char *value;
};

--edit-description::

打开编辑器并编辑文本以解释分支的用途,以供各种其他命令使用(例如请求-拉取)。

注意,它不适用于分离的HEAD分支。

这个描述被脚本request-pull使用:参见commit c016814783,还有git merge——log。

request-pull是一个脚本,用于总结两次提交到标准输出之间的更改,并在生成的摘要中包含给定的URL。

不幸的是,你不能推送描述,因为它们存储在你的配置中,这对于团队中的分支来说是无用的。

下面是一个git别名,它可以让你设置和读取当前分支的描述:

git config --global --add alias.about '!describe() { msg="$1"; git config branch."$(git rev-parse --abbrev-ref HEAD)".description ${msg:+"$msg"}; }; describe'

使用/例子:

(develop) $ git about
(develop) $ git about message
(develop) $ git about
message
(develop) $ git about "this is a new message"
(develop) $ git about
this is a new message
(develop) $ git checkout -b test_branch
Switched to a new branch 'test_branch'
(test_branch) $ git about
(test_branch) $ git about "this is the test branch"
(test_branch) $ git about
this is the test branch
(test_branch) $ git checkout -
Switched to branch 'develop'
Your branch is up to date with 'origin/develop'.
(develop) $ git about
this is a new message

特别感谢@Felicio的回答,让我开始了。