如何将所有最后一次提交时间早于2019年12月31日的分支在远程仓库中的实际名称前添加"OLD_"前缀重命名
zrrbite@ZRRBITE MINGW64 /d/dev/git/jspaint (master)
$ git for-each-ref --sort='-committerdate' --format='%(refname)%09%(committerdate)'
refs/heads | sed -e 's-refs/heads/--'
master Mon Aug 31 13:54:23 2020 +0200
newnewbr Tue Aug 28 00:08:31 2018 +0200
newbranch Tue Aug 28 00:06:51 2018 +0200
gh-pages Tue Feb 6 21:12:34 2018 +0100
some_branch Thu Feb 1 20:57:43 2018 +0100
test Thu Feb 6 18:47:16 2014 -0800
脚本:
#!/bin/bash
for k in $(git branch | sed /\*/d); do
if [ -n "$(git log -1 --before='2019-12-31' -s $k)" ]; then
git branch -m $k OLD_$k
fi
done
运行脚本后的输出:
zrrbite@ZRRBITE MINGW64 /d/dev/git/jspaint (OLD_test)
$ git branch
OLD_gh-pages
OLD_newbranch
OLD_newnewbr
OLD_some_branch
* OLD_test
#!/bin/bash
for k in $(git branch | sed /\*/d); do
if [ -n "$(git log -1 --before='2019-12-31' -s $k)" ]; then
git branch -m $k OLD_$k
git push origin --delete $k
git push origin OLD_$k
fi
done
git branch -r
(远程分支)