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
答案 0 :(得分:4)
我确认现在无法用git branch
显示分支的描述。
即将推出的v1.7.9将引入分支描述,主要用于 整合过程。我认为我们可以使它对那些用户有用 不要广泛使用request-pull / format-patch。显示简短 摘要以及“
git branch
”中的分支名称会很好。我同意让用户访问这些信息会更好 如果分支最终由您合并到主分支,从不 单独离开您的存储库。
然而,您被误导说“在...中显示简短摘要”。
分支描述支持是为用户提供一个记录有关分支的详细说明的地方,其大小类似于您通常在提交的日志消息或系列的求职信中放置的大小。
没有任何方便的地方可以做到这样的分支:(1)在开发时固有的移动目标和(2)不适合标签和笔记。已有一个简短摘要的好地方,它被称为“分支名称”。像命名函数一样命名分支。
建议的补丁“git branch --verbose-format
”尚未完成。
所以script mentioned poke仍然是(使用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);
}
答案 1 :(得分:3)
点击终端。如果您的分支有一些描述,这将显示带有描述的分支。
第1步:
vi ~/.bashrc
第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'
第3步:
source ~/.bashrc
第4步:
git-describe-branches
或强>
for line in $(git branch); do
description=$(git config branch.$line.description)
if [ -n "$description" ]; then
echo "$line $description"
fi
done
注意:
在git工作目录中运行。
如果您的分支有描述,则会显示说明。
答案 2 :(得分:2)
我知道自从被问到这个问题已经过了很长时间,但我刚开始使用分支描述并且遇到了这个寻找展示想法。
关于bash脚本答案:它只打印具有描述的分支。我想模仿git branch
输出,但也有描述。
关于perl脚本答案:格式化失败,分支名称较长。如果您处于分离的HEAD状态,它也会输出螺旋状。
我参加了python,这就是我想出的。它用以前的答案解决了我的问题。
#!/usr/bin/python
import subprocess
import sys
def git(*args):
return subprocess.check_output(['/usr/bin/git'] + list(args)).strip()
try:
branches = git('branch').split('\n')
except subprocess.CalledProcessError:
sys.exit(1)
longest = len(max(branches, key=len))
for branch in branches:
active = '*' if branch[0] == '*' else ''
branch = branch.lstrip(' *')
try:
desc = git('config', 'branch.'+branch+'.description')
except subprocess.CalledProcessError:
print '{:2}{}'.format(active, branch)
else:
print '{:2}{:{}} {}'.format(active, branch, longest, desc)
展示A
[user|host ~/git/repo((HEAD detached at origin/master))]% git bd
* (HEAD detached at origin/master)
branch_a
delete_this_after_a_little_while_pls_thx_bye long branch description
other_branch
yay_branches_amirite PR under review
展示B
[user|host ~/git/repo(other_branch_name)]% git bd
branch_a
delete_this_after_a_little_while_pls_thx_bye long branch description
* other_branch
yay_branches_amirite PR under review
展示C
[user|host ~/non_git_repo]% git bd
fatal: Not a git repository (or any of the parent directories): .git
答案 3 :(得分:1)
我从Sahil Gulati那里获得灵感并做到了这一点:
alias git-describe-branches='git branch | while read line; do
description=$(git config branch.$(echo "$line" | sed "s/\* //g").description)
echo "$line $description"
done'
示例:
$ git-describe-branches
bugfixdatum
feat32
feat53
feat56
* feat57 Projektlista
feat65
feat72
feat75 Prevent replacing lager with empty inventering
master
referens
这也打印没有描述的分支,而sed命令是因为当前分支由于星号字符需要特殊处理。
答案 4 :(得分:0)
2017年我仍然无法找到一个好的解决方案。
我想出了另一个解决方案。
更改当前分支后需要第一行才能更新BRANCH_DESCRIPTION文件。它只是使用"不执行任何编辑器"来运行编辑描述工具。然后,您只需从文件.git/BRANCH_DESCRIPTION
获取说明。
(export GIT_EDITOR=':';git branch --edit-description);
cat $GITREPOSITORY/.git/BRANCH_DESCRIPTION
注:
这可能没有记录/稳定行为。