【问题标题】:Why in my local repo, "git init" throws a fatal error, but is still creating the .git file? Then, "git status" returns fatal error "not a git repo"?为什么在我的本地仓库中,“git init”会引发致命错误,但仍在创建 .git 文件?那么,“git status”返回致命错误“not a git repo”?
【发布时间】:2022-01-29 18:28:11
【问题描述】:

刚接触 git,正在尝试学习在线课程,但我的 ubuntu 的行为与老师的不同。我在 stackoverflow 和其他网站上搜索了我的错误。我发现了类似的问题,但不是同一个问题。没有一个答案对我有帮助,所以我提出了这个新问题。

在我的本地仓库中,当我输入“git init”时,我得到:

error: chmod on /mnt/c/users/jds/documents/projects/testrepo/.git/config.lock failed: Operation not permitted

fatal: could not set 'core.filemode' to 'false'

但是,在文件夹中(如文件资源管理器中所示)我可以看到 .git 文件已创建。

如果我然后运行“git status”命令,我会得到:

fatal: not a git repository (or any parent up to mount point /mnt)

Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

Here is my ubuntu terminal, with the Windows File Explorer in the background (showing the .git file has been created in the repo)

我在 Windows 10 上,在适用于 Linux 的 Windows 子系统中运行它。

----------------- 更新 ------------------

我删除了 .git 文件并以 root 用户身份重新启动了 ubuntu。以root用户执行上述命令时,它起作用了:

root@LAPTOP-ILK7ETOO:/mnt/c/users/jds/documents/projects/testrepo# git 初始化

在中初始化空的 Git 存储库 /mnt/c/users/jds/documents/projects/testrepo/.git/

root@LAPTOP-ILK7ETOO:/mnt/c/users/jds/documents/projects/testrepo# git 状态

在主分支上

还没有提交

无需提交(创建/复制文件并使用“git add”进行跟踪)

root@LAPTOP-ILK7ETOO:/mnt/c/users/jds/documents/projects/testrepo#

但为什么我不能以指定用户的身份执行此操作?我使用“ls -l”检查了权限,并且 testrepo 启用了完全权限:

drwxrwxrwx 1 root root 512 Jan 29 18:06  testrepo

【问题讨论】:

  • 仅供参考,称其为“.git 文件”令人困惑。 Git repo 有一个.git 目录,而不是.git 文件。
  • 1.这不是与 git 相关的问题 2。这不是 SO 的问题
  • 它告诉您失败的原因以及失败的文件,但您没有查找失败的操作或查看失败的文件的权限。您知道如何查看权限,忽略了它告诉您的内容并完全去其他地方寻找。这看起来不像是在努力理解。

标签: windows git ubuntu windows-subsystem-for-linux


【解决方案1】:

为什么我不能以指定用户的身份执行此操作?

因为您的非 root 用户不能 chmod 文件,如错误消息中所述。并且“如何解决它”超出了 SO 的范围

PS - 现有的.git dir 不是功能性 Git 存储库

的标志

【讨论】:

  • 感谢您的指点。我遵循的课程演示显示非 root 用户对文件执行 chmod,所以我被误导以为我也可以。当我做不到的时候,我想也许我设置错了。所以我的重点是阅读有关设置的文档。我找错地方了。我现在将了解如何允许我的非 root 用户进行 chmod,如我正在做的课程中所示。
猜你喜欢
  • 1970-01-01
  • 2017-01-13
  • 2011-07-24
  • 1970-01-01
  • 1970-01-01
  • 2011-12-01
  • 2012-03-18
  • 2012-06-17
  • 1970-01-01
相关资源
最近更新 更多