Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
当前回答
只使用:
git config branch.<branch name>.description
在该表扬的地方表扬: https://glebbahmutov.com/blog/git-branches-with-descriptions/
其他回答
你可以使用
git config --get-regexp "branch.*.description"
使用git branch——edit-description来设置或编辑分支描述。
下面是一个shell函数,它显示与git分支类似的分支,但附加了描述。
# Shows branches with descriptions
function gb() {
current=$(git rev-parse --abbrev-ref HEAD)
branches=$(git for-each-ref --format='%(refname)' refs/heads/ | sed 's|refs/heads/||')
for branch in $branches; do
desc=$(git config branch.$branch.description)
if [ $branch == $current ]; then
branch="* \033[0;32m$branch\033[0m"
else
branch=" $branch"
fi
echo -e "$branch \033[0;36m$desc\033[0m"
done
}
下面是gb的样子,在这里显示为文本,以防图像腐烂:
$ gb
* logging Log order details. Waiting for clarification from business.
master
sprocket Adding sprockets to the parts list. Pending QA approval.
作为一个图像,你可以看到颜色:
如果您最终要使用README,请创建一个git别名,修改git checkout,以便在每次切换分支时显示您的README。
例如,在~/中添加这个。Gitconfig,在[alias]下
cor = !sh -c 'git checkout $1 && cat README' -
在此之后,您可以运行git cor <branch_name>来切换分支,并显示您要切换到的分支的README。
你可以给标签添加注释:
git tag -m 'this was a very good commit' tag1
按照惯例,您可以使用与分支名称相关的标记,或者您可以使用标记-f在主题分支的头部保留一个注释标记。
假设您想创建一个分支
git branch branch-20200328
git notes add branch-20200328 -m "This branch is for whatever"
git notes show branch-20200328