如何使用git刪除終端機中的一個變數?

如何使用git刪除終端機中的一個變數?

因此,當我嘗試在終端機中使用 git status 時遇到問題。

fatal: bad numeric config value '=' for 'color.ui': invalid unit

我研究了一下,發現我有 2 個 color.ui 變量

git config --list
credential.helper=osxkeychain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.name=Charles Pine
[email protected]
color.ui=auto
color.ui==

有誰知道如何刪除第二個color.ui?感謝您提前提供的所有協助。這是我的第一篇文章,所以如果我做錯了什麼,我真誠地道歉!

答案1

您可能會發現每個值都設定在不同的檔案中(即:系統/全域/本地)...儘管它兩個值可能都來自一個設定檔。

請參閱git config文件了解更多。

基於位置的刪除

嘗試執行以下各項,以確定錯誤條目的來源:

git config --system --get color.ui
git config --global --get color.ui
git config --local  --get color.ui

一旦確定了它的來源,請根據需要添加//--system標誌來將其刪除。例如,這裡我取消設定本地值:--global--local

git config --local --unset color.ui

基於值的刪除

如果兩個值確實來自相同文件,則也可以為該--unset模式提供與該值相符的正規表示式模式。

在您的情況( an =)中,該模式相當安全,但請注意某些特殊的正則表達式字符,例如:

  • .- 任一角色
  • *- 零個或多個
  • +- 一個或多個
  • ETC...

對你來說,這應該有效:

git config --unset color.ui =

在討論 git 配置時,可以使用以下位置:

  • --system- 系統範圍的配置
    • 儲存在${prefix}/etc/gitconfig${prefix}通常為空)
  • --global- 使用者的全域配置
    • 通常是~/.gitconfig~/.config/git/config
  • --local- 儲存庫特定的配置
    • 即:${checkout_root}/.git/config,儘管如果您在某個地方,它可能在其他地方子模組
  • --file ${filename}- 指定的另一個文件

也可以手動編輯這些文件 - 它們是基於文字的,格式類似於INI文件。這意味著你不需要使用該git config介面搜尋或修改值。

相關內容