簡體   English   中英

子模塊中的 Git 配置“錯誤的配置文件行”

[英]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 initupdateupdate --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 (在子模塊中)之后,子模塊的存儲庫恢復到可用狀態。

但是,首先那里出了什么問題?

如果可能的話,我想知道為什么會出現這個問題? 這和項目原來的平台有關系嗎? 我如何初始化子模塊有關系嗎? 我想追查問題的原因,以避免將來發生。

  1. 盡管在 Windows 中, git像 UNIX 程序一樣思考,所以正斜杠是正確的。 有關在 Windows git中使用正斜杠的一些示例,請參閱http://gitbyexample.org/
  2. 你的回購中有些東西壞了。 我不確定是什么,但在與它斗爭太多之前,你能重新克隆嗎? 從舊的頂級目錄重命名project1project1.fubar和重做git clone foo://project1和您的目錄應該結束了正確的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM