Lar*_*ann 137 git git-submodules
是否有一些简单的方法来重命名git子模块目录(除了完成删除它并重新添加新目标名称的整个动作 ).
虽然我们在这,但为什么我不能在父目录中执行以下操作: git mv old-submodule-name new-submodule-name
Von*_*onC 200
Git1.8.5(2013年10月)应简化流程.只需做一个:
git mv A B
Run Code Online (Sandbox Code Playgroud)
"
git mv A B",当移动子模块时A,已经教会重新定位其工作树并调整.gitmodules文件中的路径.
在提交0656781fadca1中查看更多:
目前
git mv在子模块上使用" "会将子模块的工作树移动到超级项目的工作树中.但子模块的路径设置.gitmodules保持不变,现在与工作树不一致,并使git命令依赖于正确的path -> name mapping(如status和diff)行为奇怪.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.gitmodulesfile and stage both.
This doesn't happen when no.gitmodulesfile 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.gitmodulesfile or has already updated the path setting by hand before issuing the "git mv" command (in which case the warning reminds him thatmvwould have done that for him).
Only when.gitmodulesis found and contains merge conflicts themvcommand will fail and tell the user to resolve the conflict before trying again.
git 2.9 (June 2016) will improve git mv for submodule:
请参阅Stefan Beller()提交a127331(2016年4月19日).(由Junio C Hamano合并- -在提交9cb50a3,2016年4月29日)stefanbeller
gitster
mv:允许移动嵌套的子模块"
git mv old new"没有正确调整作为目录内部子目录的子模块的路径old/.然而,子模块需要更新它们到git目录的链接以及对
.gitmodules文件的更新.
Mar*_*wak 89
我发现以下工作流程工作:
mv oldpath newpathgit rm oldpathgit add newpathgit submodule sync注意:此方法不会在2018版本的GIT中正确更新索引和.gitmodules.
$ mv submodule-oldpath submodule-newpath
$ git rm submodule-oldpath
$ git add submodule-newpath
$ git submodule sync
Run Code Online (Sandbox Code Playgroud)
这个解决方案对我不起作用,因为在使用git add命令时,子模块作为简单目录而不是子模块包含在项目中.
正确的解决方案是:
$ mv submodule-oldpath ~/another-location
$ git rm submodule-oldpath
$ git submodule add submodule-repository-URL submodule-newpath
Run Code Online (Sandbox Code Playgroud)
资料来源:http://bcachet.github.io/development/2012/05/25/rename-git-submodule/
我刚刚尝试了上面提到的一些建议.我在跑:
$ git --version
git version 1.8.4
Run Code Online (Sandbox Code Playgroud)
我发现最好取消初始化子模块,删除目录并创建一个新的子模块.
git submodule deinit <submodule name>
git rm <submodule folder name>
git submodule add <address to remote git repo> <new folder name>
Run Code Online (Sandbox Code Playgroud)
至少这对我最有用.因人而异!
无法对其进行重命名,因此您必须先将其删除 ( deinit) 并重新添加。
所以删除后:
git submodule deinit <path>
git rm --cached <path>
Run Code Online (Sandbox Code Playgroud)
您还可以仔细检查并删除对它的引用:
.gitmodules.git/config.git/modules/<name>(最好进行备份)中删除引用文件夹,因为每个文件夹都有一个config文件,它保留对其的引用worktree然后通过将任何更改提交到您的存储库来暂存您的更改:
git commit -am 'Removing submodule.'
Run Code Online (Sandbox Code Playgroud)
并通过以下方式仔细检查您是否没有任何未解决的问题:
git submodule update
git submodule sync
git submodule status
Run Code Online (Sandbox Code Playgroud)
所以现在你可以再次添加 git 子模块:
git submodule add --name <custom_name> git@github.com:foo/bar.git <my/path>
Run Code Online (Sandbox Code Playgroud)
MacOs:当我想使用VonC 解决方案将子模块文件夹更改Common为小写时:
git mv Common common
Run Code Online (Sandbox Code Playgroud)
我明白了
致命:重命名“Common”失败:参数无效
解决方案 - 使用一些临时文件夹名称并移动两次:
git mv Common commontemp
git mv commontemp common
Run Code Online (Sandbox Code Playgroud)
就这样 :)
| 归档时间: |
|
| 查看次数: |
44851 次 |
| 最近记录: |