Anda mungkin menyukai item kecil ini ... Ini menarik daftar dan meminta konfirmasi untuk setiap item sebelum akhirnya menghapus semua pilihan ...
git branch -d `git for-each-ref --format="%(refname:short)" refs/heads/\* | while read -r line; do read -p "remove branch: $line (y/N)?" answer </dev/tty; case "$answer" in y|Y) echo "$line";; esac; done`
Gunakan -D untuk memaksa penghapusan (seperti biasa).
Agar mudah dibaca, berikut ini adalah garis putus-putus ...
git branch -d `git for-each-ref --format="%(refname:short)" refs/heads/\* |
while read -r line; do
read -p "remove branch: $line (y/N)?" answer </dev/tty;
case "$answer" in y|Y) echo "$line";;
esac;
done`
di sini adalah pendekatan xargs ...
git for-each-ref --format="%(refname:short)" refs/heads/\* |
while read -r line; do
read -p "remove branch: $line (y/N)?" answer </dev/tty;
case "$answer" in
y|Y) echo "$line";;
esac;
done | xargs git branch -D
akhirnya, saya suka memiliki ini di .bashrc saya
alias gitselect='git for-each-ref --format="%(refname:short)" refs/heads/\* | while read -r line; do read -p "select branch: $line (y/N)?" answer </dev/tty; case "$answer" in y|Y) echo "$line";; esac; done'
Dengan begitu aku bisa bilang begitu
gitSelect | xargs git branch -D.
git branch -D $(git branch | grep 3.2*)- ini bekerja untuk saya. Ini menghapus cabang yang namanya dimulai dengan "3.2".grep- pencocokan pola dalam output (git branchdalam hal ini).$()- Berarti mengeksekusi dan menempatkan hasilnya.|- rantai.