Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
Git中是否有一种为分支提供“描述”的方法?
虽然我尝试使用描述性的名称,但在一个分支上工作一段时间,有时会使我对为什么要创建其他一些主题分支的记忆变得模糊。我尝试为分支使用描述性的名称,但我认为“描述”(关于分支目的的简短说明)会很好。
当前回答
只使用:
git config branch.<branch name>.description
在该表扬的地方表扬: https://glebbahmutov.com/blog/git-branches-with-descriptions/
其他回答
下面是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 branch branch-20200328
git notes add branch-20200328 -m "This branch is for whatever"
git notes show branch-20200328
只使用:
git config branch.<branch name>.description
在该表扬的地方表扬: https://glebbahmutov.com/blog/git-branches-with-descriptions/
我非常确定目前不支持该特性。我认为最好的办法是创建一个描述文本文件,基本上是一个README,在包含您想要的信息的分支中。
Chris J建议的README可以工作,只要它使用.gitattribute中定义的自定义合并驱动程序进行设置。 这样,在合并期间始终保留README的本地版本。
分支的“描述”也被称为与元数据相关联的“注释”,它是不受支持的。
至少,对于一个README文件,你可以对任何分支执行:
$ git show myBranch:README
如果你的README在你的REPO的根目录,它将从任何路径工作,因为git show使用的路径是绝对的一个从REPO的顶部目录。