![](/img/trans.png)
[英]git: 'credential-cache' is not a git command - Remove setting
[英]git: 'credential-cache' is not a git command
我完全按照這些說明進行操作,包括有關密碼緩存的部分。 似乎說明是錯誤的,因為每次我git push origin master
我都會收到此錯誤:
git: 'credential-cache' is not a git command. See 'get --help'.
...此時我被迫輸入我的用戶名和密碼。 這樣做之后,我再次看到相同的錯誤消息,然后是git push
的輸出。
這是我的 .gitconfig 文件的內容:
[user]
name = myusername
email = myusername@myemaildomain.com
[credential]
helper = cache
需要明確的是,在我安裝 Git 並運行 Git Bash 之后,這正是我輸入的內容:
git config --global user.name "myusername"
git config --global user.email "myusername@myemaildomain.com"
git config --global credential.helper cache
請幫忙。 這太令人沮喪了!
從我發現的博客中:
這個 [git-credential-cache] 不適用於 Windows 系統,因為 git-credential-cache 通過 Unix 套接字進行通信。
用於 Windows 的 Git
由於 msysgit 已被 Git for Windows 取代,因此現在使用Git for Windows是最簡單的選擇。 某些版本的 Git for Windows 安裝程序(例如 2.7.4)在安裝期間有一個復選框以啟用 Git 憑據管理器。 這是一個屏幕截圖:
還在使用 msysgit? 對於 msysgit 版本 1.8.1 及更高版本
在 msysgit 1.8.1 中添加了wincred
助手。 按如下方式使用它:
git config --global credential.helper wincred
對於早於 1.8.1 的 msysgit 版本
首先,下載git-credential-winstore並將其安裝在您的 git bin 目錄中。
接下來,確保包含git.cmd
的目錄在您的 Path 環境變量中。 默認目錄是 64 位系統上的C:\Program Files (x86)\Git\cmd或 32 位系統上的C:\Program Files\Git\cmd 。 一個簡單的測試方法是啟動命令提示符並輸入git
。 如果您沒有獲得 git 命令列表,則說明設置不正確。
最后,啟動命令提示符並鍵入:
git config --global credential.helper winstore
或者您可以手動編輯.gitconfig
文件:
[credential]
helper = winstore
完成此操作后,您可以通過 Windows 憑據管理器管理您的 git 憑據,您可以通過 Windows 控制面板調出該管理器。
看起來git
現在在 Windows (msysgit) 上帶有開箱即用的wincred
:
git config --global credential.helper wincred
參考: https ://github.com/msysgit/git/commit/e2770979fec968a25ac21e34f9082bc17a71a780
git config --global credential.helper wincred
CONTROL PANEL\CREDENTIAL MANAGER\WINDOWS CREDENTIAL\GENERIC CREDENTIAL
Internet or network address:
添加git:https://
{username} .github.com
User:
{姓名}Password:
{密碼}我在 windows7 上使用 AptanaStudio3 時遇到了這個問題。 這幫助了我:
git config --global credential.helper wincred
對於 git version >=1.7.10 (檢查git --version
),使用此方法(來自參考):
視窗:
git config --global credential.helper wincred
蘋果電腦:
git config --global credential.helper osxkeychain
類似的錯誤是'credential-wincred' is not a git command
wincred
用於不再維護的項目 git-credential-winstore 。
從上面的鏈接下載版本為 zip 文件並將內容提取到
\cygwin\usr\libexec\git-core
(或\cygwin64\usr\libexec\git-core
可能是)
然后啟用它,(通過設置全局.gitconfig
) - 執行:
git config --global credential.helper manager
如何使用
無需進一步配置。
它在需要憑據時 [自動] 工作。
例如,當推送到 Azure DevOps 時,它會打開一個窗口並初始化 oauth2 流以獲取您的令牌。
參考:
現在有一種更簡單的方法來設置 Git 密碼緩存,方法是在 Windows 上雙擊一個小exe 。 該程序仍然基於投票最多的答案中提到的git-credential-winstore
,盡管該項目已從 GitHub 移至http://gitcredentialstore.codeplex.com/
您可以從此博客文章下載 exe(和 Mac 的二進制文件): https ://github.com/blog/1104-credential-caching-for-wrist-friendly-git-usage
我通過從特定項目的配置中刪除credential
部分來解決此問題:
git config -e
[credential] helper = cache
。這消除了煩人的消息:
git: 'credential-cache' is not a git command. See 'git --help'.
為了解決這個問題的其他人,我在 Ubuntu 中遇到了同樣的問題(即我的密碼沒有緩存,盡管正確設置了選項,並且得到錯誤git: 'credential-cache' is not a git command.
),直到我發現這個功能只在 Git 1.7.9 及更高版本中可用。
在舊的 Ubuntu 發行版上(Natty;我是一個頑固的 Gnome 2 用戶),repo 中的版本是 git 版本 1.7.4.1。 我使用以下 PPA 進行升級: https ://launchpad.net/~git-core/+archive/ppa
為了其他人有這個問題 - 我來到這里是因為我試圖讓我如何設置一個新的 github 存儲庫變得可愛,但是根據設置頁面憑據幫助程序不起作用,除非你克隆一個存儲庫。
“提示:憑據幫助程序僅在您克隆 HTTPS 存儲庫 URL 時起作用。如果您改用 SSH 存儲庫 URL,則使用 SSH 密鑰進行身份驗證。本指南提供生成和使用 SSH 密鑰對的幫助。”
當我嘗試從主分支使用命令“git pull”時,我也遇到了類似的錯誤。
Error: "git: 'credential-manager' is not a git command. See 'git --help'."
我執行了以下兩個命令並解決了問題。
$ git config --global --unset credential.helper
$ git config credential.helper store
我意識到我的談話有點晚了,但我遇到了完全相同的問題在我的 git config 中我有兩個條目憑據......
在我的 .gitconfig 文件中
[credential]
helper = cached
[credentials]
helper = wincred
修復:將我的 .gitconfig 文件更改為以下設置
[credential]
helper = wincred
[credentials]
helper = wincred
這對我有用:
git credential-manager-core configure
在較舊的 Ubuntu Linux 系統上:
git config --global credential.helper store
我真的只是經歷了這個!
Account Settings > Emails
。 你應該看到這樣的東西: git config --global user.name "yourusername"
git config --global user.email "1234567+yourgithubusername@users.noreply.github.com"
git config --global credential.helper cache
現在,您的 git 命令應該可以再次工作了。
小提示:我使用的是 Linux Mint。 YMMV
附加說明:Git Credential Manager Core v 2.0.567 在他們的 Debian backage 中有一個錯誤。 請在新版本發布前安裝v2.0.474 。
我的 .gitconfig 的 [credential] 部分中有三個不同的helper=
條目,其中一個是空的。 刪除其他兩個並保留helper=wincred
為我解決了這個問題。
順便說一句:我不知道為什么,但我沒有立即找到我的 .gitconfig。 然后我在 C:\Users\username 中找到了它。
我卸載密碼管理器,所以你必須把密碼放在每個人
git credential-manager uninstall
在我們的域更改后,我們的 Azure DevOps 存儲庫也遇到了同樣的問題,即從 @xy.com 到 @xyz.com。 為了解決這個問題,我們生成了一個新的具有以下權限的個人訪問令牌:
代碼:讀&寫 打包:讀
然后我們打開 Windows 憑據管理器,添加一個新的通用 Windows 憑據,其中包含以下詳細信息:
Internet 或網絡地址: “git:{ projectname }@dev.azure.com/{ projectname }” - 或者,您應該在此處使用您的 git 存儲庫名稱。
用戶名: “個人訪問令牌”
密碼: {生成的個人訪問令牌}
之后我們所有的 git 操作都重新開始工作了。 希望這對其他人有幫助!
在 mac 上運行以下命令:
git config --global credential.helper osxkeychain
我最初的答案結果證明即使對我自己也不是很有用,所以我仔細研究了一下,發現了一個 hack(雖然有點復雜)。
因此,我在 MSYS2 下使用git
,並且我想使用credential-cache
來臨時記住我的密碼(而且我還沒有看到使用wincred
或其他適用於 Windows 的方法的這種用例)。
基本上,這需要在https://github.com/git/git/blob/55144cc/builtin/credential-cache--daemon.c#L239中進行破解 - 而不是在該行中die
,我們想繼續。
所以,首先,我們要在 MSYS2 下構建git
。
因此,我們需要構建 MSYS2 中使用的實際git
。 首先,檢查版本:
$ git --version
git version 2.33.0
$ pacman -Ss git | grep installed # msys/git 2.33.0-1 (VCS) [installed]
然后,按照https://www.msys2.org/wiki/Creating-Packages/ ,我們可以這樣做:
$ git clone "https://github.com/msys2/MSYS2-packages"
$ cd MSYS2-packages/
$ cd git
$ makepkg -sCLf
==> Making package: git 2.33.0-1 (Thu, Sep 23, 2021 12:47:33 PM)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Installing missing dependencies...
...
make[1]: Entering directory '/c/src/MSYS2-packages/git/src/git-2.33.0'
make[1]: 'GIT-VERSION-FILE' is up to date.
make[1]: Leaving directory '/c/src/MSYS2-packages/git/src/git-2.33.0'
sed -e '1s|#!.*/sh|#!/bin/sh|' git-subtree.sh >git-subtree
chmod +x git-subtree
make: Leaving directory '/c/src/MSYS2-packages/git/src/git-2.33.0/contrib/subtree'
==> Starting check()...
注意這里:
*** prove ***
部分結束,這需要更長的時間,但可以用 Ctrl-C 中斷,並且構建的可執行文件不會被刪除。所以,現在我們想在源代碼中做一個 hack; 筆記:
makepkg -sCLf
,因為這將擦除源目錄(以及所有構建的 .exe 人工制品),然后在構建之前重建它因此,我們使用sed
進行 hack,然后構建:
$ sed -i 's/die(_(permissions_advice), dir);/fprintf(stderr, "Permissions on cached credentials socket directory %s are too loose, but HACK: going on\\n", dir);/' ./src/git-2.33.0/builtin/credential-cache--daemon.c
$ (cd src/git-2.33.0/; make)
CC builtin/credential-cache--daemon.o
LINK git.exe
...
SUBDIR templates
在這一點上,請注意,黑客最終至少包含三個可執行文件,可以通過以下方式確認:
$ grep -ao ....HACK........ ./src/git-2.33.0/git-credential-cache--daemon.exe
$ grep -ao ....HACK........ ./src/git-2.33.0/git-credential-cache.exe
$ grep -ao ....HACK........ ./src/git-2.33.0/git.exe
...在替換所有三個之后,我只能讓它工作:
# backup the original files:
$ mv /usr/lib/git-core/git-credential-cache--daemon.exe /usr/lib/git-core/__git-credential-cache--daemon_orig.exe
$ mv -v /usr/lib/git-core/git-credential-cache.exe /usr/lib/git-core/__git-credential-cache__orig.exe
$ mv -v /usr/bin/git.exe /usr/bin/__git_orig.exe
$ mv -v /usr/lib/git-core/git.exe /usr/lib/git-core/__git_orig.exe
# copy over the hacked files:
cp -v ./src/git-2.33.0/git-credential-cache--daemon.exe /usr/lib/git-core/
cp -v ./src/git-2.33.0/git-credential-cache.exe /usr/lib/git-core/
cp -v ./src/git-2.33.0/git.exe /usr/bin/
cp -v ./src/git-2.33.0/git.exe /usr/lib/git-core/
此時, credential-cache
也開始在 MSYS2 上為我工作(在有限的時間內緩存密碼); 只是它在啟動時轉儲了被黑的行:
$ git pull
Password for 'https://user@git.mysite.com':
Permissions on cached credentials socket directory /home/user/.cache/git/credential are too loose, but HACK: going on
Already up to date.
# second pull, password is cached
$ git pull
Already up to date.
有點棘手,但似乎有效。
PS:一個棘手的事情是,我最初只是用printf
替換了die
到stdout
,但是一直失敗; 事實證明, stdout
用於進程間通信,為了成功,顯然在stdout
上回答ok\0
是三個字節; 所以解決方案是將通知打印到stderr
。
(原答案):
雖然沒有完全按照要求回答問題,但這是我能找到的最合適的問題,將其記錄為答案:
我在 Windows 10 的 MSYS2 下使用git
,目前有以下版本:
$ git --version
git version 2.32.0
我通常只想讓 git 在有限的時間內(可能 10 分鍾左右)緩存我的密碼,然后忘記它; 而且我還沒有看到wincred
或其他特定於 Windows 的憑據管理器在該用例中的使用。
話雖這么說,但對我來說有一個“簡單的解決方法”——基本上,憑證管理器第一次運行就可以了; 只有在隨后的使用中,我才得到:
$ git push
Password for 'http://user@githost.example.com':
fatal: The permissions on your socket directory are too loose; other
users may be able to read your cached credentials. Consider running:
chmod 0700 /home/user/.cache/git/credential
fatal: cache daemon did not start:
Enumerating objects: 8, done.
Counting objects: 100% (8/8), done.
...
所以,基本上,修復是刪除credential
目錄 - 此后,憑證緩存管理器就像第一次運行一樣,並在有限的時間內緩存密碼 - 就像我想要的那樣:
$ rm -rf ~/.cache/git/credential
# note below, the very first pull still asks for a password:
$ git pull
Password for 'http://user@githost.example.com':
Already up to date.
# ... but the second pull does not, it uses credentials cache
$ git pull
Already up to date.
對我來說已經足夠好了,我猜:)
編輯:不是真的,我在此之后立即體驗到,如果您嘗試拉入另一個選項卡,錯誤就會返回。
當前與 Git for Windows(2.32,2021 年第 2 季度)打包的憑證助手是
git config credential.helper
manager-core
where git-credential-manager-core
C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe
這是在 GCM-core(Git Credential Manager Core)之后:microsoft/Git-Credential-Manager-Core/
Git Credential Manager Core (GCM Core) 是基於 .NET 構建的安全 Git 憑證助手,可在 Windows 和 macOS 上運行。 Linux 支持處於早期預覽階段。
與 Git 的內置憑證助手(Windows:wincred,macOS:osxkeychain,Linux:gnome-keyring)相比,GCM Core 為Azure DevOps提供單因素身份驗證支持、Azure DevOps Server(以前稱為 Team Foundation Server)、GitHub 和 Bitbucket。
Git Credential Manager Core (GCM Core) 取代了基於 .NET Framework 的Git Credential Manager for Windows (GCM)和基於 Java 的Git Credential Manager for Mac 和 Linux (Java GCM) ,在所有平台上提供一致的身份驗證體驗。
隨着 Git 2.34(2021 年第四季度),Unix 套接字開始考慮用於 Windows 的 Git:
請參閱Carlo Marcelo Arenas Belón ( carenas
)的提交 bb390b1 、 提交 245670c 、 提交 0fdcfa2 (2021 年 9 月 14 日)。
(由Junio C Hamano -- gitster
--在提交 c2e7990中合並,2021 年 9 月 23 日)
git-compat-util
:在 windows 中包含 unix 套接字的聲明簽字人:Carlo Marcelo Arenas Belón
自 Windows 10 版本 1803 和 Windows Server 2019 起可用。
NO_UNIX_SOCKETS
仍然是 Windows 構建的默認值,因為它們需要保持與 Windows 7 之前的版本的向后兼容性,但允許包含標頭。
在我的情況下,這個命令解決了這個問題:
git config --global credential.helper manager-core --replace-all
用於使用新的 net-core 憑證管理器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.