[英]Git config "bad config file line" in a submodule
我在 Windows 和 Linux 上使用 git,最近我遇到了一个只在 Windows 上出现的奇怪问题......假设我有两个项目。 两者都在 git 中进行了版本控制,并且每个都有一个子模块。
子模块配置位于C:\\Projects\\project1\\.git\\modules\\plugins\\tasks\\config
,如下所示:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
worktree = ..\..\..\..\plugins\tasks
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = ssh://domain/repo/path
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
子模块配置位于C:\\Projects\\project2\\.git\\modules\\doc\\preamble\\config
,我也在下面提供:
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
worktree = ../../../../doc/preamble
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
url = ssh://domain/another/repo/path
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
总而言之,配置文件之间唯一真正的区别是工作目录路径中的/
和\\
。
我在 Git Bash 中操作。 当我在项目 1及其子模块中执行git status
(以及其他一些简单命令)时:
/c/Projects/project1 (devel) $ git status
fatal: bad config file line 6 in c:/Projects/project1/.git/modules/plugins/tasks/config
fatal: 'git status --porcelain' failed in submodule plugins/tasks
/c/Projects/project1/plugins/tasks $ git status
fatal: bad config file line 6 in d:/Projects/project1/.git/modules/plugins/tasks/config
/c/Projects/project1 (devel) $ git submodule sync -- plugins/tasks/
Synchronizing submodule url for 'plugins/tasks'
fatal: bad config file line 6 in c:/Projects/project1/.git/modules/plugins/tasks/config
此外, git submodule init
或update
或update --init
没有输出,也不会改善情况。
而当我在Project 2 中使用git
时,一切正常。
您会认为天真的解决方案是手动替换子模块配置中的斜杠,更复杂的解决方案是编写一个脚本,在所有受影响的子模块中执行此操作。
不幸的是,实际上,将第一个配置中的路径更改为:
worktree = ..\..\..\..\plugins\tasks
到:
worktree = ../../../../plugins/tasks
导致不同的错误:
/c/Projects/project1/plugins/tasks $ git status
fatal: bad object HEAD
当我查看文件c/Projects/project1/.git/modules/plugins/tasks/refs/master
那里有问题,因为里面的 SHA1 是:
0000000000000000000000000000000000000000
此时,在我执行git reset --hard origin/master
(在子模块中)之后,子模块的存储库恢复到可用状态。
但是,首先那里出了什么问题?
如果可能的话,我想知道为什么会出现这个问题? 这和项目原来的平台有关系吗? 我如何初始化子模块有关系吗? 我想追查问题的原因,以避免将来发生。
git
像 UNIX 程序一样思考,所以正斜杠是正确的。 有关在 Windows git
中使用正斜杠的一些示例,请参阅http://gitbyexample.org/ 。project1
到project1.fubar
和重做git clone foo://project1
和您的目录应该结束了正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.