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

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


当前回答

假设您想创建一个分支

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

其他回答

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

下面是Greg Hewgill提到的git分支命令的一个可能实现:

#!/usr/bin/perl

sub clean {
    map { s/^[\s\*]*\s// } @_;
    map { s/\s*$// } @_;
    return @_;
}

sub descr {
    $_ = `git config branch.@_.description`;
    s/\s*$//;
    return $_;
};
sub indent {
    $_ = shift;
    s/^/      /mg;
    return $_;
};

my @branches = clean `git branch --color=never --list`;
my %merged = map { $_ => 1 } clean `git branch --color=never --merged`;

for my $branch (@branches) {
    my $asis = `git branch --list --color=always $branch`;
    $asis =~ s/\s*$//;
    print "  $asis";
    print " \033[33m(merged)\033[0m" if ($merged{$branch} and $branch ne "master");
    print "\n";

    print indent descr $branch;
    print "\n";
    print "\n";
}

你可以使用

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

只使用:

git config branch.<branch name>.description

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

Use

git branch --list -v

显示上游分支:

git branch --list -vv

添加-r只显示远程或-a显示远程和本地。