我需要从我们的远程代码库中删除旧的且无人维护的分支。我正在尝试找到一种按其最后修改日期列出远程分支的方法,但我找不到。
有没有简便的方法以这种方式列出远程分支?
我需要从我们的远程代码库中删除旧的且无人维护的分支。我正在尝试找到一种按其最后修改日期列出远程分支的方法,但我找不到。
有没有简便的方法以这种方式列出远程分支?
这里有一个函数,您可以添加到bash_profile中,以使此操作更加便捷。
在Git仓库中使用:
branch
打印所有本地分支branch -r
打印所有远程分支函数:
branch() {
local pattern="s/^..//"
local arg=""
if [[ $@ == "-r" ]]; then
pattern="s/^..(.*?)( ->.*)?$/\1/"
arg=" -r "
echo '-r provided'
fi
for k in $(git branch $arg | perl -pe "$pattern"); do
echo -e $(git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" $k -- | head -n 1)\\t$k
done | sort -r
}
或者您可以使用我的PHP脚本,https://gist.github.com/2780984
#!/usr/bin/env php
<?php
$local = exec("git branch | xargs $1");
$lines = explode(" ", $local);
$limit = strtotime("-2 week");
$exclude = array("*", "master");
foreach ($exclude as $i) {
$k = array_search($i, $lines);
unset($lines[$k]);
}
$k = 0;
foreach ($lines as $line) {
$output[$k]['name'] = $line;
$output[$k]['time'] = exec('git log '.$line.' --pretty=format:"%at" -1');
if ($limit>$output[$k]['time']) {
echo "This branch should be deleted $line\n";
exec("git branch -d $line");
}
$k++;
}
?>
git branch -v --sort='-authordate:iso8601' --format='%(align:width=50)%(refname:short)%(end)%(authordate:relative)'
upscale-zone-a-3 11 minutes ago
master 17 minutes ago
value-metric-type 2 days ago