Git无响应。

4

为什么我无法推送到远程仓库?

> git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
 (use "git push" to publish your local commits)

nothing to commit, working tree clean


> git push

> git push --verbose

我没有忘记输出,只是它不存在。这种情况从未发生过。

根据我的经验,95%的时候,git的问题都与凭据有关。 所以我尝试强制git要求我输入它们:

> git push -v --verbose

没有任何内容。

今天早晨我很开心地在推进项目,期间没有碰过任何东西......

编辑(回答问题/添加信息):

> git remote -v

origin  https://myusername-admin@bitbucket.org/myusername/someproject.git (fetch)
origin  https://myusername-admin@bitbucket.org/myusername/someproject.git (push)

> git --version

git version 2.37.3.windows.1

> Get-ComputerInfo | select WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer

WindowsProductName WindowsVersion OsHardwareAbstractionLayer
------------------ -------------- --------------------------
Windows 10 Home    2009           10.0.19041.1806 

我没有这两个环境变量:

> gci env:* | sort-object name | grep GIT_DIR
> gci env:* | sort-object name | grep GIT_WORK_TREE

我的Path环境变量中只有C:\Program Files\Git\cmd

当我尝试使用Sourcetree时,得到的行为也是相同的。

这也没有显示任何内容:

> git config --global credential.helper

尽管我已经在Windows凭据管理器中保存了Bitbucket凭据,并一直使用这些凭据进行身份验证,但我现在在使用GitHub托管的其他存储库时也遇到了同样的问题。至少现在我收到一个弹出错误:enter image description here。编辑(已解决):通过卸载并重新安装Git,问题已得到解决。

你能够联系到远程吗?换句话说,也许在你和他们之间有一个网络连接中断。无论他们是谁。 - torek
我已经编辑了答案,建议使用SSH而不是HTTPS进行测试,以防有所帮助。 - VonC
我已编辑了问题,以便您可以检查bitbucket存储的凭据。 - VonC
1
这是 git config --global credential.helper 命令,其中 credential 中有一个 "a",而不是 credentil - VonC
2个回答

3
您需要检查使用的Git版本、操作系统以及设置了哪些环境变量(例如GIT_DIRGIT_WORK_TREE可能会影响git pull等命令)。

但也可以尝试使用不同的工具进行相同的操作(例如Visual Studio Code或Eclipse,后者使用自己基于Java的Git,称为JGit)。这样,您就可以知道行为是否一致。


如果HTTPS无法使用,请尝试切换到SSH URL:

git remote set-url origin git@bitbucket.org:myusername/someproject.git

(确保先在您的Bitbucket账户中设置SSH密钥

请检查凭据管理器缓存的HTTPS凭据:

git config --global credential.helper

根据您的操作系统和助手值,该助手可能无法使用缓存凭据进行响应。
在Windows上,假设助手设置为manager-core,请使用CMD(无需bash)检查您的凭据:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set "GH=%ProgramFiles%\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

printf "host=bitbucket.org\nprotocol=https\nusername=myusername-admin"| git-credential-manager-core get

OP确认了一个问题与credential.helper(空)有关。

OP的解决方案:卸载并重新安装git。


最终我通过卸载并重新安装git来解决了问题。感谢你的建议! - IDK
@IDK 好的。我已经将你的解决方案包含在答案中以增加可见性。 - VonC

1

尝试检查是否有远程代码库

git remote -v

如果有,则

git push <你的分支名>

或者...

  • 尝试更改文件
  • git add <文件>
  • git commit -m '提交'
  • git push

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接