Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
当前回答
你可以给标签添加注释:
git tag -m 'this was a very good commit' tag1
按照惯例,您可以使用与分支名称相关的标记,或者您可以使用标记-f在主题分支的头部保留一个注释标记。
其他回答
Use
git branch --list -v
显示上游分支:
git branch --list -vv
添加-r只显示远程或-a显示远程和本地。
假设您想创建一个分支
git branch branch-20200328
git notes add branch-20200328 -m "This branch is for whatever"
git notes show branch-20200328
如果您最终要使用README,请创建一个git别名,修改git checkout,以便在每次切换分支时显示您的README。
例如,在~/中添加这个。Gitconfig,在[alias]下
cor = !sh -c 'git checkout $1 && cat README' -
在此之后,您可以运行git cor <branch_name>来切换分支,并显示您要切换到的分支的README。
你可以使用
git config --get-regexp "branch.*.description"
下面是一个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的回答,让我开始了。