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

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


当前回答

假设您想创建一个分支

git branch branch-20200328
git notes add branch-20200328 -m "This branch is for whatever"
git notes show branch-20200328

其他回答

git config --global --add alias.about '!describe() { git config branch."$1".description; }; describe'

命令将定义全局选项别名。About as shell表达式。如果在存储库中运行git about <branch>,将显示分支的描述。

我非常确定目前不支持该特性。我认为最好的办法是创建一个描述文本文件,基本上是一个README,在包含您想要的信息的分支中。

选定的答案对我来说似乎太夸张了。我倾向于维护每个分支的描述文件,这是一个正常的源代码控制文件,比如master.txt, dev.txt等,如果有一个难以处理的数字或分支,我会创建一个层次结构来更好地组织它。

假设您想创建一个分支

git branch branch-20200328
git notes add branch-20200328 -m "This branch is for whatever"
git notes show branch-20200328

使用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.

作为一个图像,你可以看到颜色: