简体   繁体   English

如何重命名git子模块,保留对包含子模块的git存储库的子模块提交的引用?

[英]How to rebase git submodule preserving references to submodule commits from git repository containing the submodule?

(Currently I'm fixing my old repositories before publishing.) (目前我正在修复我的旧存储库,然后才发布。)

I already know how to rewrite commit author e-mail and name in git history . 我已经知道如何在git历史中重写提交作者的电子邮件和名称

I have a git project with submodules. 我有一个带子模块的git项目。 I want to rewrite history of these submodules, but because I fast-forward these submodules during development, I want to modify links from main git repo pointing to some of these submodules commits to links pointing to new commits after submodule rebase. 我想重写这些子模块的历史记录,但是因为我在开发过程中快速转发这些子模块,我想修改主git repo中指向某些子模块的链接提交到指向子模块rebase之后的新提交的链接。 Ie I need to rebase git submodule in conjunction with rebasing git repository containing this submodule. 即我需要将git子模块与包含此子模块的rebased git存储库结合使用。 (Sorry, for too long text, I don't know how to describe that shorter.) (对不起,文字太久了,我不知道如何描述那么短。)

How to rewrite git submodule history in sync with git repository history containing the submodule? 如何与包含子模块的git存储库历史记录同步重写git子模块历史记录?

As I mentioned in " Repository with submodules after rewriting history of submodule ", there is no easy solution. 正如我在“ 重写子模块历史后的子模块存储库 ”中提到的,没有简单的解决方案。

You will have to rewrite the history of your main repo with git filter-branch , looking for specific commits including a gitlink ( special entry in the index ) 您将不得不使用git filter-branch重写主仓库的历史记录,寻找特定的提交,包括gitlink索引中的特殊条目

You need first to establish a correspondence between the SHA1 of the submodule old history and the gitlinks used by your main repo 首先需要在子模块旧历史的SHA1和主仓库使用的gitlink之间建立对应关系

 cd /submodule/repo/just/rewritten/
 # the old history is still available in refs/original
 git -C /path/to/rewritten/repo for-each-ref --format="%(refname)" refs/original

 cd /main/repo
git for-each-ref --contains <SHA1> # SHA being a SHA1 from the old submodule history

Then you will need to replace 然后你需要更换

git filter-branch --prune-empty --tree-filter 'change_gitlink'

change_gitlink would be a script that would go into the submodule folder (hence --tree-filter , and not --index-filter ), checkout the new SHA1 (from the new history of the submodule). change_gitlink将是一个进入子模块文件夹的脚本(因此--tree-filter ,而不是--index-filter ),签出新的SHA1(来自子模块的新历史记录)。 The filter branch would commit the new repo state, including the new gitlink (because the submodule was checked out at the right new SHA1) 过滤器分支将提交新的repo状态,包括新的gitlink(因为子模块已在右侧的新SHA1中检出)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM