英文:
How to migrate specific files from Mercurial to gitlab with commit history?
问题
我有一个案例,需要将Mercurial(Hg)中的一个文件夹迁移到GitLab(不是整个仓库),并保留其历史记录。
我找到了hg-fast-export,但不确定是否可以将仅有的几个文件导出到GitLab。如果可以,请告诉我如何操作。
提前致谢。
英文:
I have a case to migrate only one folder from Mercurial(Hg) to Gitlab (not the entire repository) with its history.
I came across hg-fast-export but I am not sure if we can export only a few files to GitLab. If yes suggest to me how to do this.
Thanks in advance.
答案1
得分: 3
使用hg convert
与filemap
选项的一个好方法是首先创建一个包含你感兴趣的文件夹的临时Mercurial仓库,然后仅将该仓库导入Gitlab。
当你通过
--filemap
选项提供映射时,Convert
还可以在转换过程中过滤或重命名文件。文件映射是一个指定要包含、重命名或省略哪些文件的文件。默认情况下,所有文件都会被包含(空的文件映射表示包括所有文件)。
每行可以包含以下指令之一:
包括路径/到/文件
排除路径/到/文件
重命名从/文件到/文件
请注意,当你使用convert
时,它会生成一个全新的仓库,与原始仓库没有“关联”。因此,变更集ID将不同。看起来这不会对你正在做的事情造成任何损害。
英文:
A good way to do this would be to use hg convert
with the filemap
option to first create a second temporary Mercurial repository which contains only the folder your are interested in, and then import just that to Gitlab.
> Convert
can also filter or rename files during conversion, when you
> supply it a mapping via the --filemap
option.
>
> The filemap is a file that specifies which files are to be included,
> renamed, or omitted. By default all files are included (empty filemap
> means include everything).
>
> Each line can contain one of the following directives:
>
> include path/to/file
>
> exclude path/to/file
>
> rename from/file to/file
Note that when you use convert it produces an entirely new repository that is not "related" to the original. So changeset IDs will be different. Seems like this won't cause any harm for what you are doing.
答案2
得分: 1
一个干净的方法是将folder1用于您的Mercurial存储库,将folder2用于您的Git存储库。您可以获取Mercurial存储库中的所有修订哈希,然后:
- 对于每个提交哈希
- 在folder1中检出该哈希
- 用folder1的内容覆盖folder2中您感兴趣的任何文件
- 提交
这可以自动化为一个命令行bash脚本。
英文:
A clean way to do it would be to have folder1 for your mercurial repo and folder2 for your git repo. You could get all the revision hashes in your Mercurial repo and then:
- for each commit hash
- check out that hash in folder1
- override any files of your interest at folder2 with the content of folder1
- commit
This can be automatized into a command-line bash script.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论