Git/linux 多合一查找命令
Git/linux all-in-one find command
我有一个 nix 命令遍历目录中的所有 git 存储库并切换到默认分支。
最后一行应该删除所有列出的分支。它在单独执行时有效,但在该命令中无效。我尝试过转义 `,在其周围加上引号,...但我无法让它工作。
这是我得到的错误:
fatal: branch name required
如果有人有任何建议,我将不胜感激:)
PS:我知道这不是最佳做法,您应该自动删除内容等...这就是我使用“-d”而不是“-D”的原因。这也是为了清理我的环境,因为随着时间的推移,我倾向于拥有多个带有很多分支的回购协议。
find . \
-maxdepth 2 -type d \
-name ".git" \
-execdir python3 -c 'import os; print("[33m---------------------------------------------- " + os.path.abspath(".") + " ----------------------------------------------[0m")' \; \
-execdir git checkout development \; \
-execdir git branch -d `git for-each-ref --format="%(refname:short)" 'refs/heads/bugfix' 'refs/heads/feature' 'refs/heads/release' 'refs/heads/hotfix' 'refs/heads/master'` \;
试试这个:
find . \
-maxdepth 2 -type d \
-name ".git" \
-execdir echo git checkout development \; \
-execdir python3 -c 'import os; print("[33m---------------------------------------------- " + os.path.abspath(".") + " ----------------------------------------------[0m")' \; \
-execdir bash -c 'branches="$(git for-each-ref --format="%(refname:short)" refs/heads/bugfix refs/heads/feature refs/heads/release refs/heads/hotfix refs/heads/master)"; test -n "$branches" && echo git branch -d "$branches" || echo "No branch found"' \;
当你看到它做了你想要的时,删除 2 个回声。
最好用 2 个命令或 shell
脚本来简化它。
#!/bin/bash
# array of all .git
mapfile -t all_dot_git < <(find . -maxdepth 2 -type d -name '.git');
# loop over them and do what ever you want
for dir in ${all_dot_git[@]};do
echo $dir;
done
示例输出:
./blog/.git
./wh_ticket_bot/.git
./ipwebcam-gst/.git
./gitlab-tmp/.git
./project/.git
./curly/.git
./wh_tools_bot/.git
./derak-website/.git
./bash-CLI-template/.git
./ldc/.git
./btc/.git
./en4fa.ir/.git
./sshpf/.git
./ppst/.git
./png/.git
./gitlab-docker/.git
./migrate/.git
./fflive/.git
./wp-docker-pattern/.git
./wh-tools-bot/.git
./derak-panel-review/.git
./oxv/.git
./101-tutorial/.git
./shakibamoshiribot/.git
./high-traffic-site-optimization/.git
./isms/.git
./dotvim/.git
在帮助下检查分支名称或pushd
和popd
#!/bin/bash
# array of all .git
mapfile -t all_dot_git < <(find . -maxdepth 2 -type d -name '.git');
# loop over them and do what ever you want
for dir in ${all_dot_git[@]};do
# set actual path (remove .git)
dir=$(dirname $dir);
# or just ${dir%/*} variable substitution
# cd to $dir
pushd $dir
# do the task
git branch;
# return back to first place
popd;
done
示例输出:
./blog
~/git-repo/blog ~/git-repo
* main
~/git-repo
./wh_ticket_bot
~/git-repo/wh_ticket_bot ~/git-repo
add_ticket_support
* master
~/git-repo
./ipwebcam-gst
~/git-repo/ipwebcam-gst ~/git-repo
* master
~/git-repo
./gitlab-tmp
~/git-repo/gitlab-tmp ~/git-repo
dev
* master
staging
~/git-repo
./project
...
...
我有一个 nix 命令遍历目录中的所有 git 存储库并切换到默认分支。 最后一行应该删除所有列出的分支。它在单独执行时有效,但在该命令中无效。我尝试过转义 `,在其周围加上引号,...但我无法让它工作。
这是我得到的错误:
fatal: branch name required
如果有人有任何建议,我将不胜感激:)
PS:我知道这不是最佳做法,您应该自动删除内容等...这就是我使用“-d”而不是“-D”的原因。这也是为了清理我的环境,因为随着时间的推移,我倾向于拥有多个带有很多分支的回购协议。
find . \
-maxdepth 2 -type d \
-name ".git" \
-execdir python3 -c 'import os; print("[33m---------------------------------------------- " + os.path.abspath(".") + " ----------------------------------------------[0m")' \; \
-execdir git checkout development \; \
-execdir git branch -d `git for-each-ref --format="%(refname:short)" 'refs/heads/bugfix' 'refs/heads/feature' 'refs/heads/release' 'refs/heads/hotfix' 'refs/heads/master'` \;
试试这个:
find . \
-maxdepth 2 -type d \
-name ".git" \
-execdir echo git checkout development \; \
-execdir python3 -c 'import os; print("[33m---------------------------------------------- " + os.path.abspath(".") + " ----------------------------------------------[0m")' \; \
-execdir bash -c 'branches="$(git for-each-ref --format="%(refname:short)" refs/heads/bugfix refs/heads/feature refs/heads/release refs/heads/hotfix refs/heads/master)"; test -n "$branches" && echo git branch -d "$branches" || echo "No branch found"' \;
当你看到它做了你想要的时,删除 2 个回声。
最好用 2 个命令或 shell
脚本来简化它。
#!/bin/bash
# array of all .git
mapfile -t all_dot_git < <(find . -maxdepth 2 -type d -name '.git');
# loop over them and do what ever you want
for dir in ${all_dot_git[@]};do
echo $dir;
done
示例输出:
./blog/.git
./wh_ticket_bot/.git
./ipwebcam-gst/.git
./gitlab-tmp/.git
./project/.git
./curly/.git
./wh_tools_bot/.git
./derak-website/.git
./bash-CLI-template/.git
./ldc/.git
./btc/.git
./en4fa.ir/.git
./sshpf/.git
./ppst/.git
./png/.git
./gitlab-docker/.git
./migrate/.git
./fflive/.git
./wp-docker-pattern/.git
./wh-tools-bot/.git
./derak-panel-review/.git
./oxv/.git
./101-tutorial/.git
./shakibamoshiribot/.git
./high-traffic-site-optimization/.git
./isms/.git
./dotvim/.git
在帮助下检查分支名称或pushd
和popd
#!/bin/bash
# array of all .git
mapfile -t all_dot_git < <(find . -maxdepth 2 -type d -name '.git');
# loop over them and do what ever you want
for dir in ${all_dot_git[@]};do
# set actual path (remove .git)
dir=$(dirname $dir);
# or just ${dir%/*} variable substitution
# cd to $dir
pushd $dir
# do the task
git branch;
# return back to first place
popd;
done
示例输出:
./blog
~/git-repo/blog ~/git-repo
* main
~/git-repo
./wh_ticket_bot
~/git-repo/wh_ticket_bot ~/git-repo
add_ticket_support
* master
~/git-repo
./ipwebcam-gst
~/git-repo/ipwebcam-gst ~/git-repo
* master
~/git-repo
./gitlab-tmp
~/git-repo/gitlab-tmp ~/git-repo
dev
* master
staging
~/git-repo
./project
...
...