Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
当前回答
下面是一个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的回答,让我开始了。
其他回答
Chris J建议的README可以工作,只要它使用.gitattribute中定义的自定义合并驱动程序进行设置。 这样,在合并期间始终保留README的本地版本。
分支的“描述”也被称为与元数据相关联的“注释”,它是不受支持的。
至少,对于一个README文件,你可以对任何分支执行:
$ git show myBranch:README
如果你的README在你的REPO的根目录,它将从任何路径工作,因为git show使用的路径是绝对的一个从REPO的顶部目录。
Use
git branch --list -v
显示上游分支:
git branch --list -vv
添加-r只显示远程或-a显示远程和本地。
只使用:
git config branch.<branch name>.description
在该表扬的地方表扬: https://glebbahmutov.com/blog/git-branches-with-descriptions/
你可以给标签添加注释:
git tag -m 'this was a very good commit' tag1
按照惯例,您可以使用与分支名称相关的标记,或者您可以使用标记-f在主题分支的头部保留一个注释标记。
选定的答案对我来说似乎太夸张了。我倾向于维护每个分支的描述文件,这是一个正常的源代码控制文件,比如master.txt, dev.txt等,如果有一个难以处理的数字或分支,我会创建一个层次结构来更好地组织它。