gpt4 book ai didi

git - 将 git 子模块移动到另一个目录后失败,错误为 'git status --porcelain' failed in submodule

转载 作者:IT王子 更新时间:2023-10-29 01:16:20 28 4
gpt4 key购买 nike

最初我有以下(简化的) repo 结构:

MyRepo
external1/MySub (git submodule)
.gitsubmodules

在哪里

$ cat .gitsubmodules

[submodule "external1/MySub"]
path = external1/MySub
url = user@repo:/remoterepo/externals/MySub.git

然后我想将 MySubmodule 移动到同一个 git 存储库中的另一个目录,例如 external2 所以结构如下:

MyRepo
external2/MySub (git submodule)
.gitsubmodules

我所做的和所想的就足够了,我只是将(通过操作系统 mv)external1/MySub 目录移动到 external2/MySub并将 .gitsubmodules 文件编辑为:

$ cat .gitsubmodules

[submodule "external2/MySub"]
path = external2/MySub
url = user@repo:/remoterepo/externals/MySub.git

此更改后,我收到以下错误:

$ git status

fatal: Could not chdir to '../../../../../repo/external/MySub': No such file or directory
fatal: 'git status --porcelain' failed in submodule repo/external2/MySub

我错过了什么?是否需要进行任何其他更改才能使此类移动生效?

(我在 Windows 8.1 上使用 git 版本 1.8.3rc3)

最佳答案

I simply moved the external1/MySub directory to external2/MySub

按照mv移动(unix 命令),或 git mv (git 命令)?

您需要移动 special entrythe index代表父仓库的子模块。

通常,(阅读 git mv ),这应该足够了:

git mv external1/MySub external2/MySub

Moving a submodule using a gitfile (which means they were cloned with a Git version 1.7.8 or newer) will update the gitfile and core.worktree setting to make the submodule work in the new location.
It also will attempt to update the submodule.<name>.path setting in the gitmodules file and stage that file (unless -n is used).

这最适合最新的 1.8.5 git(例如 msysgit for Windowslatest package for Unix)


Suseika添加 in the comments

If you get message

fatal: renaming '%submodule%' failed: No such file or directory

it is probably because you're adding a directory level, e.g. moving submodule "math" to "libs/math".
git mv doesn't create missing [intermediate] directories, you should mkdir them yourself.


git 2.9(2016 年 6 月)将改进 git mv对于子模块:

参见 commit a127331 (2016 年 4 月 19 日)Stefan Beller ( stefanbeller ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 9cb50a3 ,2016 年 4 月 29 日)

mv: allow moving nested submodules

"git mv old new" did not adjust the path for a submodule that lives as a subdirectory inside old/ directory correctly.

submodules however need to update their link to the git directory as well as updates to the .gitmodules file.


Git 2.12(2017 年第一季度)提供了将嵌套子模块移动到父仓库的功能:

有一个新的子模块助手“ git submodule absorbgitdirs ”,可以更轻松地移动嵌入式 .git/中的子模块目录 super 项目 .git/modules/ (并将后者指向前者已添加为“gitdir:”文件)。

参见 commit 7c4be45 (2016 年 12 月 27 日),commit f6f8586 , commit 47e83eb , commit 1a248cf (2016 年 12 月 12 日),和 commit 6f94351 , commit 89c8626 , commit 90c0011 , commit 6f94351 , commit 89c8626 , commit 90c0011 (2016 年 12 月 8 日)Stefan Beller ( stefanbeller ) .
(由 Junio C Hamano -- gitster -- merge 于 commit da2b74e ,2017 年 1 月 10 日)

submodule: add absorb-git-dir function

When a submodule has its git dir inside the working dir, the submodule support for checkout that we plan to add in a later patch will fail.

Add functionality to migrate the git directory to be absorbed into the superprojects git directory.

The newly added code in this patch is structured such that other areas of Git can also make use of it. The code in the submodule--helper is a mere wrapper and option parser for the function absorb_git_dir_into_superproject, that takes care of embedding the submodules git directory into the superprojects git dir. That function makes use of the more abstract function for this use case relocate_gitdir, which can be used by e.g. the worktree code eventually to move around a git directory.


注意:仍然存在(Git 2.14.x/2.15,2017 年第 4 季度)与子模块移动相关的错误:请参阅“Git: moving submodules recursively (nested submodules)”。


Git 2.15.x/2.16(2018 年第一季度)将使移动子模块更加健壮,因为“git fetch --recurse-submodules”现在知道子模块可以除了获得更新之外,还在 super 项目中四处走动,并找到需要相应获取的那些。

参见 commit 4b4aced , commit c68f837 (2017 年 10 月 16 日),和 commit 01ce122 (2017 年 10 月 6 日)Heiko Voigt ( hvoigt ) .
(由 Junio C Hamano -- gitster -- merge 于 commit b4d658b ,2017 年 11 月 6 日)

implement fetching of moved submodules

We store the changed submodules paths to calculate which submodule needs fetching. This does not work for moved submodules since their paths do not stay the same in case of a moved submodules.
In case of new submodules we do not have a path in the current checkout, since they just appeared in this fetch.

It is more general to collect the submodule names for changes instead of their paths to include the above cases. If we do not have a configuration for a gitlink we rely on constructing a default name from the path if a git repository can be found at its path. We skip non-configured gitlinks whose default name collides with a configured one.


请注意,在 Git 2.19(2018 年第 3 季度)之前,在使用 --recurse-submodules 获取期间,尝试查看子模块中是否需要获取的代码当子模块的路径在提交范围内更改时感到困惑 super 项目,有时显示“(null)”。
这已得到纠正。

参见 commit c3749f6 , commit 5fc8475 (2018 年 6 月 14 日)作者:Stefan Beller ( stefanbeller ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 085d2ab ,2018 年 6 月 28 日)

submodule: fix NULL correctness in renamed broken submodules

When fetching with recursing into submodules, the fetch logic inspects the superproject which submodules actually need to be fetched.
This is tricky for submodules that were renamed in the fetched range of commits. This was implemented in c68f837 (implement fetching of moved submodules, 2017-10-16, Git v2.16.0), and this patch fixes a mistake in the logic there.

关于git - 将 git 子模块移动到另一个目录后失败,错误为 'git status --porcelain' failed in submodule,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20991138/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com