打印分支说明

bpw*_*621 12 git

Git支持一个名为--edit-description的分支命令选项,它指出它由"各种"其他命令使用.一个命令(至少默认情况下)不使用它是git branch(当用于简单列出本地分支时).有没有办法让git分支显示分支描述(详细选项看起来只是添加了分支上的最后一次提交)?

要清楚,我想要像下面这样的东西

> git branch
* master      I am the alpha and the omega
  bugfix1     This is the fix to that thing
  future      Transition to the new architecture
Run Code Online (Sandbox Code Playgroud)

Von*_*onC 6

我确认目前无法用显示分支的描述git branch

该线程包括

即将发布的v1.7.9将引入分支描述,主要用于集成过程。我认为我们可以使它对不大量使用request-pull / format-patch的用户有用。在“ git branch”中显示简短的摘要以及分支名称会很好。

我同意,即使分支最终被您合并到master分支并且永远不会自己离开存储库,也可以为用户提供访问信息的权限。

但是,您被误导了“在...旁边显示简短摘要”。

分支描述支持是给用户一个地方,以记录有关分支的详细说明,其大小类似于您通常在提交日志或系列求职信中放置的大小。
对于这样的分支,没有任何方便的地方:(1)本质上是在开发目标时移动的目标,而(2)并不是标签和注释的理想选择。

已经有一个简短摘要的好地方,它被称为“分支名称”。命名分支就像命名函数一样。

建议的补丁“ git branch --verbose-format”尚未完成。

所以剧本 中提到,遗体(用git的别名),目前唯一的解决办法:

#!/bin/perl

$output= `git branch`;

foreach my $line (split(/^/, $output)) {
  my ($is_current, $name) = split(/\s+/, $line);
  my $description = `git config branch.$name.description`;

  $description =~ s/\s+$//;
  printf("%1s %-22s %s\n", $is_current, $name, $description);
}
Run Code Online (Sandbox Code Playgroud)


Sah*_*ati 6

在终端上点击这个。如果您的分支有一些描述,这将显示带有描述的分支。

步骤1:

vi ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

第2步: 把这个

alias git-describe-branches='for line in $(git branch); do 
     description=$(git config branch.$line.description)
     if [ -n "$description" ]; then
       echo "$line     $description"
     fi
done'
Run Code Online (Sandbox Code Playgroud)

步骤3:

source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

步骤4:

git-describe-branches
Run Code Online (Sandbox Code Playgroud)

或者

for line in $(git branch); do 
     description=$(git config branch.$line.description)
     if [ -n "$description" ]; then
       echo "$line     $description"
     fi
done
Run Code Online (Sandbox Code Playgroud)

笔记:

  1. 在 git 工作目录中运行它。

  2. 如果您的分支有描述,将显示描述。