是否有一些简单的方法来重命名git子模块目录(而不是从头到脚删除它,然后用新的目标名称重新添加它)。
当我们在它的时候,为什么我不能在父目录中做以下事情:git mv old-submodule-name new-submodule-name
是否有一些简单的方法来重命名git子模块目录(而不是从头到脚删除它,然后用新的目标名称重新添加它)。
当我们在它的时候,为什么我不能在父目录中做以下事情:git mv old-submodule-name new-submodule-name
当前回答
我只是尝试了上面建议的一些。我运行:
$ git --version
git version 1.8.4
我发现最好是去初始化子模块,删除目录并创建一个新的子模块。
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
至少这对我来说是最有效的。YMMV !
其他回答
Git1.8.5(2013年10月)应该可以简化这个过程。简单地做一个:
git mv A B
"git mv A B",当移动一个子模块A时,已经教它重新定位它的工作树,并调整.gitmodules文件中的路径。
参见commit 0656781fadca1:
Currently using "git mv" on a submodule moves the submodule's work tree in that of the superproject. But the submodule's path setting in .gitmodules is left untouched, which is now inconsistent with the work tree and makes git commands that rely on the proper path -> name mapping (like status and diff) behave strangely. Let "git mv" help here by not only moving the submodule's work tree but also updating the "submodule.<submodule name>.path" setting from the .gitmodules file and stage both. This doesn't happen when no .gitmodules file is found and only issues a warning when it doesn't have a section for this submodule. This is because the user might just use plain gitlinks without the .gitmodules file or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him that mv would have done that for him). Only when .gitmodules is found and contains merge conflicts the mv command will fail and tell the user to resolve the conflict before trying again.
git 2.9(2016年6月)将改进子模块的git mv:
参见Stefan Beller (stefanbeller)的commit a127331(2016年4月19日)。 (由Junio C Hamano合并- gitster -在提交9cb50a3, 2016年4月29日)
Mv:允许移动嵌套子模块 "git mv old new"没有正确调整old/ directory中作为子目录存在的子模块的路径。 子模块需要更新到git目录的链接 以及更新。gitmodules文件。
正确的解决方法是:
mv oldpath ~/another-location
git rm oldpath
git submodule add submodule-repository-URL newpath
MacOs:当我想使用VonC解决方案将子模块文件夹Common改为小写时:
git mv Common common
我得到
fatal:重命名“Common”失败:无效参数
解决方案-使用临时文件夹名并移动两次:
git mv Common commontemp
git mv commontemp common
这就是全部:)
我发现以下工作流程:
.gitmodules最新消息 接近新手机 得一个人去 晚上好,夫人 什么
注意:这种方法不会在2018年版本的GIT中正确更新索引和. GIT模块。
注意:你现在可以只执行git mv oldpath newpath,就像VonC的回答中指出的那样。(确保您使用的是最新版本的git)
编辑.gitmodules文件重命名子模块,然后重命名子模块目录。
我认为你可能需要做一个git子模块同步之后,但我现在不在一个位置检查。