重命名 git 子模块
有没有一些简单的方法来重命名 git 子模块目录(除了执行 删除它并使用新的目的地名称重新添加)。
当我们这样做时,为什么我根本无法在父目录中执行以下操作: git mv old-submodule-name new-submodule-name
Is there some easy way to rename a git submodule directory (other than going through the entire motion of deleting it and re-adding it with a new destination name).
And while we are at it, why is it that I simply cannot do the following in the parent directory: git mv old-submodule-name new-submodule-name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
编辑 .gitmodules 文件以重命名子模块,然后重命名子模块目录。
我认为您可能需要随后执行 git submodulesync,但我现在无法检查。
Edit the .gitmodules file to rename the submodule and then rename the submodule directory.
I think you might need to do a
git submodule sync
afterwards, but I'm not in a position to check right now.许多很棒的答案,我最近遇到了这个问题(遇到了一些困难),我想分享我所采取的完整(但最少)步骤列表。
处理具体示例:
存储库 PyShallow ([GitHub] : CristiFati/pyshallow - PyShallow):
取决于 PyCFUtils ([GitHub]:CristiFati/pycfutils - PyCFUtils)并将其作为(Git)子模块:
我最近将其从 CFPyUtils 重命名为(在 GitHub 上)
有一点让我有点偏离方向,那就是旧的 URL(使用旧名称)仍然有效 - GitHub 足够智能,可以重定向到新的(这是有道理的)
我可能被认为太迂腐,但我希望删除所有对CFPyUtils的引用(即使其中一些只是内部的(用户不可见)并且它们可以工作)
步骤 (如果想用新替换旧 - 每个术语都指:路径和(部分) URL):
重命名 Git 存储库中的子模块文件夹(
git mv old new
).gitmodules:编辑和替换新出现的所有旧次
.git /config:编辑所有旧出现的内容并替换为新
重命名(手动)子模块引用文件夹(
mv .git/modules/old .git/modules/new
)new/.git (!!!这是一个文件!!!):更新新的参考文件夹
同步子模块(
git 子模块同步
)修改引用旧子模块路径的任何(非 Git 相关)文件
之后在测试克隆以及新克隆上一切正常。
实际步骤:
Many great answers, I recently ran into this issue (had a bit of struggle) and I want to share a complete (yet minimal) list of steps that I took.
Working on a concrete example:
Repository PyShallow ([GitHub]: CristiFati/pyshallow - PyShallow):
Depends on PyCFUtils ([GitHub]: CristiFati/pycfutils - PyCFUtils) and has it as a (Git) submodule:
I recently renamed it (on GitHub) from CFPyUtils
One thing that threw me me a bit off course is that the old URL (with the old name) still works - GitHub is smart enough to redirect to the new one (which makes sense)
I might be considered too pedantic, but I wanted all references to CFPyUtils removed (even if some of them are just internal (no visibility to the user) and they work)
Steps (if one wants to replace old by new - each term refers to both: path and (part of) URL):
Rename submodule folder in the Git repository (
git mv old new
).gitmodules: Edit and replace all old occurrences by new
.git/config: Edit and replace all old occurrences by new
Rename (manually) submodule reference folder (
mv .git/modules/old .git/modules/new
)new/.git (!!! it's a file !!!): Update the new reference folder
Synchronize submodule (
git submodule sync
)Modify any (non Git related) file that references the old submodule path
Everything works fine afterwards on the test clone, and also on a fresh one.
The actual steps:
Git1.8.5(2013 年 10 月)应该简化过程。只需做一个:
更多信息请参见提交 0656781fadca1:
git 2.9(2016 年 6 月)将改进子模块的 git mv:
请参阅commit a127331 (2016 年 4 月 19 日)作者:Stefan Beller (
stefanbeller
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 9cb50a3,2016 年 4 月 29 日)Git1.8.5 (October 2013) should simplify the process. Simply do a:
See more in commit 0656781fadca1:
git 2.9 (June 2016) will improve
git mv
for submodule:See commit a127331 (19 Apr 2016) by Stefan Beller (
stefanbeller
).(Merged by Junio C Hamano --
gitster
-- in commit 9cb50a3, 29 Apr 2016)我发现以下工作流程有效:
mv oldpath newpath
git rm oldpath
git add newpath
git submodulesync
注意:此方法无法在 2018 版本的 GIT 中正确更新索引和 .gitmodules 。
注意:您现在可能可以执行 git mv oldpath newpath ,如 VonC 的答案。 (确保您使用的是最新版本的git)
I found following workflow working:
mv oldpath newpath
git rm oldpath
git add newpath
git submodule sync
Note: this approach does not update the index and
.gitmodules
properly in 2018 versions of GIT.Note: You may be able to just do
git mv oldpath newpath
now, as pointed out in VonC's answer. (Ensure you are using the latest version of git)正确的解决方案是:
The correct solution is:
无法重命名它,因此您必须先将其删除 (
deinit
),然后再次添加。因此,删除它后:
您还可以仔细检查并删除对它的引用:
.gitmodules
.git/config
.git/modules/ 中删除引用文件夹
(最好进行备份),因为每个文件夹都有config
文件,其中保存对其worktree
的引用,然后通过提交来暂存更改通过以下方式对您的存储库进行任何更改:
并通过以下方式仔细检查您是否没有任何未解决的问题:
所以现在您可以再次添加 git 子模块:
It's not possible to rename it, so you've to remove it first (
deinit
) and add it again.So after removing it:
you may also double check and remove the references to it in:
.gitmodules
.git/config
.git/modules/<name>
(best to make a backup), as each folder hasconfig
file where it keeps the reference to itsworktree
then stage your changes by committing any changes to your repo by:
and double check if you don't have any outstanding issues by:
so now you can add the git submodule again:
我只是尝试了上面建议的一些。我正在运行:
我发现最好取消初始化子模块,删除目录并创建一个新的子模块。
至少这对我来说是最好的。嗯嗯!
I just tried a few of the suggested above. I'm running:
I found it was best to de-init the submodule, remove the directory and create a new submodule.
At least that is what worked for me best. YMMV!
MacOs:当我想使用VonC解决方案更改子模块文件夹时
Common
改为小写:我明白
解决方案 - 使用一些临时文件夹名称并移动两次:
仅此而已:)
MacOs: When I wanna use VonC solution to change submodule folder
Common
to lowercase:I get
Solution - use some temporary folder name and move twice:
That's all :)