windows - 没有工作树就无法使用 Git-Windows-git-pull

标签 windows git github

我在 Windows 上遇到与 Git 相关的问题,无法从 git 上的存储库中提取更改。我能够添加、提交和推送我的更改,但不能 pull 。

它给了我一个错误: 致命:C:**\Git/libexec/git-core/git-pull 不能在没有 工作树。

在搜索这个错误时,我得到了一些关于 SO 的链接,它要求删除工作树或工作目录环境变量。这个链接似乎更多地解释了 git 是如何工作的,而不是引用如何解决它,并且似乎没有一个特定于 Windows。所以我发布这个问题

我的不是一个裸存储库,这里是 git 配置文件内容:

 [core]
    repositoryformatversion = 0
    filemode = false
    bare = false
    logallrefupdates = true
    symlinks = false
    ignorecase = true
    hideDotFiles = dotGitOnly
[remote "origin"]
    fetch = +refs/heads/*:refs/remotes/origin/*
    url = https://<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f4818791869a959991b4939d809c8196da979b99" rel="noreferrer noopener nofollow">[email protected]</a>/Project/projectname.git
[branch "master"]
    remote = origin
    merge = refs/heads/master

我第一次在 Windows 上使用 git,我使用 mysgit。我是否需要设置其他参数或一些特定于 Windows 的环境变量,就像在 ubuntu 上使用 git 一样,无需特殊步骤。

还引用了此链接,但似乎不是最新的,因为本文中指定的内容都不存在。 Link

如有任何建议或帮助,我们将不胜感激。

谢谢,请告诉我这个问题是否适合这个论坛,或者我应该将其发布给 super 用户。

编辑:

Eckes 发帖后,它帮助我找出了缺少工作树的错误。

我正在使用的工作站安装了另一个版本的 git,当我检查环境变量时,它被设置为它,一旦我清理它,我就不再收到之前的错误了,但是 pull 仍然无法工作,出现错误:


编辑

 remote: Counting objects: 132, done.
 remote: Compressing objects: 100% (64/64), done.
 remote: Total 104 (delta 74), reused 70 (delta 40)
 Receiving objects: 100% (104/104), 33.05 KiB, done.
 Resolving deltas: 100% (74/74), completed with 24 local objects.
 fatal: write failure on 'stdout': Bad file descriptor
 error: https://github.com/Project/projectname.git did not send all necessary objects

最佳答案

这很奇怪。查看 Git/libexec/git-core/git-pull (从 git version 1.7.11.msysgit.0 开始),有命令

require_work_tree_exists

该命令在Git/libexec/git-core/git-sh-setup中实现:

require_work_tree_exists () {
  if test "z$(git rev-parse --is-bare-repository)" != zfalse
  then
    die "fatal: $0 cannot be used without a working tree."
  fi
}

因此,如果您真的不在裸露的存储库中(即您发布的 .git/config 实际上是您的存储库),则不会打印发出消息。

但是 Git/libexec/git-core/git-sh-setup 中有另一个命令打印出该字符串:

require_work_tree () {
  test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
  die "fatal: $0 cannot be used without a working tree."
}

我建议更改两条消息中的其中一条,以便能够确定哪一条与您真正相关。如果您在非 git repo 目录的目录上发出 git 命令,则会发出第二个命令。只是为了确定:git pull 必须在 git 存储库内运行...


编辑:
为了检查出了什么问题,请在 git bash 上尝试 require_work_tree_exists 代码。它不应进入代码的 then 部分。

关于windows - 没有工作树就无法使用 Git-Windows-git-pull,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11292057/

相关文章:

c# - 从 Windows 服务打印,无对话框,无用户交互

windows - Windows 的 'man' 程序(打开 UNIX 手册页的程序)在哪里?

git - 为什么 `git -C` 在 Python 的 post receive hook 中不起作用?

ios - 在 iOS 应用程序中实现 "Login with Github"的问题

angularjs - 在 github.io 中创建 json 服务器

windows - 在 Windows 上编译 MatConvNet

windows - 如何将长参数粘贴到 Windows 中的调试器中?

ruby-on-rails - 使用 git 进行标记和修复的适当策略

git - 为什么我的 TeamCity 构建停止工作?

github - 有没有链接可以显示 GitHub 中的所有公共(public)存储库?