我經常不小心錯誤地簽出遠程跟蹤分支:
git checkout -b origin/fixbugs
本-b應該是一個-t。
這個錯誤創建了一個名為“origin/fixbugs”的分支。當分支名稱以“origin/”(或任何其他遠程名稱)開頭時,如何讓 git 給我一個錯誤而不是創建這個分支?
uj5u.com熱心網友回復:
首先,您不必使用該-t選項,因為它git checkout有一個guess mode。
git checkout fixbugs
如果
<branch>未找到,但在一個遠程(呼叫它<remote>)中確實存在一個具有匹配名稱--no-guess且未指定的跟蹤分支,則視為等效于:$ git checkout -b <branch> --track <remote>/<branch>
其次,使用新git switch命令(使用Git 2.23 , Q3 2019):
- 它具有與 相同的猜測模式
git checkout,所以一個簡單的git switch fixbugs就足夠了。 - if 有一個
-t選項,但沒有-b選項,所以在這種情況下你會得到一個錯誤!
uj5u.com熱心網友回復:
從 v2.28 開始,reference-transaction您可以使用一個掛鉤來審查所有此類更新。
#!/bin/bash
case $1 in
prepared)
while IFS='/ ' read old new refs type name rest; do
if [[ $type != remotes && $new = *[^0]* ]] && git config remote.$name.url >&-
then echo $name${rest: /$rest} would pun remote name $name
exit 1
fi
done
;;
esac
除非您已經開始使用多級遠程名稱,否則會這樣做,如果您愿意,可以加強檢查回圈。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/409112.html
標籤:
