คุณอาจชอบรายการเล็ก ๆ นี้ ... มันจะดึงรายการและขอการยืนยันของแต่ละรายการก่อนที่จะลบการเลือกทั้งหมดในที่สุด ...
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`
ใช้ -D เพื่อบังคับการลบ (เหมือนปกติ)
เพื่อความสะดวกในการอ่านนี่คือการแยกบรรทัดทีละบรรทัด ...
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`
นี่คือวิธีการ 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
ในที่สุดฉันชอบที่จะมีสิ่งนี้ใน. bashrc ของฉัน
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'
ด้วยวิธีนี้ฉันสามารถพูดได้
gitSelect | xargs git branch -D.
git branch -D $(git branch | grep 3.2*)- สิ่งนี้ใช้ได้สำหรับฉัน มันจะลบสาขาที่ชื่อขึ้นต้นด้วย "3.2"grep- การจับคู่รูปแบบในผลลัพธ์ (จากgit branchในกรณีนี้)$()- หมายถึงดำเนินการและวางผลลัพธ์|- การผูกมัด