[英]Git config "bad config file line" in a submodule
I use git on Windows and Linux, and I have recently ran into a strange issue that manifests only on Windows... Let's say I have two projects.我在 Windows 和 Linux 上使用 git,最近我遇到了一个只在 Windows 上出现的奇怪问题......假设我有两个项目。 Both are versioned in git, and each has a submodule.
两者都在 git 中进行了版本控制,并且每个都有一个子模块。
the submodule config is located in C:\\Projects\\project1\\.git\\modules\\plugins\\tasks\\config
and looks like this:子模块配置位于
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
The submodule configuration is located in C:\\Projects\\project2\\.git\\modules\\doc\\preamble\\config
, and I also provide it below:子模块配置位于
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
To sum up, the only real difference between the configuration files is the /
and \\
in paths to working directory.总而言之,配置文件之间唯一真正的区别是工作目录路径中的
/
和\\
。
I operate in Git Bash.我在 Git Bash 中操作。 When I do
git status
(and some other simple commands) in Project 1 and its submodule:当我在项目 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
Also, git submodule init
or update
or update --init
give no output, and don't improve the situation.此外,
git submodule init
或update
或update --init
没有输出,也不会改善情况。
While, when I use git
in Project 2 , everything is ok.而当我在Project 2 中使用
git
时,一切正常。
You'd think that the naive solution is to substitute the slashes in the submodule config by hand, more elaborate solution would be to write a script that does that in all affected submodules.您会认为天真的解决方案是手动替换子模块配置中的斜杠,更复杂的解决方案是编写一个脚本,在所有受影响的子模块中执行此操作。
Unfortunately, actually, changing the path in 1st config from:不幸的是,实际上,将第一个配置中的路径更改为:
worktree = ..\..\..\..\plugins\tasks
to:到:
worktree = ../../../../plugins/tasks
results in a different error:导致不同的错误:
/c/Projects/project1/plugins/tasks $ git status
fatal: bad object HEAD
and when I look into the file c/Projects/project1/.git/modules/plugins/tasks/refs/master
something is wrong there, as the SHA1 inside is:当我查看文件
c/Projects/project1/.git/modules/plugins/tasks/refs/master
那里有问题,因为里面的 SHA1 是:
0000000000000000000000000000000000000000
At this point, after I did git reset --hard origin/master
(in the submodule) the repository of the submodule was restored to usable state.此时,在我执行
git reset --hard origin/master
(在子模块中)之后,子模块的存储库恢复到可用状态。
But, what went wrong there in the first place?但是,首先那里出了什么问题?
If possible, I would like to know why did this issue even occur?如果可能的话,我想知道为什么会出现这个问题? Does this have anything to do with the original platform of the project?
这和项目原来的平台有关系吗? Does it matter how I initialize the submodule?
我如何初始化子模块有关系吗? I would like to track down the reason of the issue to avoid it in the future.
我想追查问题的原因,以避免将来发生。
git
thinks like a UNIX program so forward slashes are the right thing.git
像 UNIX 程序一样思考,所以正斜杠是正确的。 See http://gitbyexample.org/ for some examples of using forward slashes in Windows git
.git
中使用正斜杠的一些示例,请参阅http://gitbyexample.org/ 。project1
to project1.fubar
and redo git clone foo://project1
and your directories should end up correct.project1
到project1.fubar
和重做git clone foo://project1
和您的目录应该结束了正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.