如何在不丢失分支的情况下将 mercurial 存储库转换为 git 存储库? [英] How to convert mercurial repository to git repository without losing branches?

查看:30
本文介绍了如何在不丢失分支的情况下将 mercurial 存储库转换为 git 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 mercurial repo 转换为 git repo.其实我做了,但我没有看到分支.转换 repo 后,我只能看到一个分支(作为主分支),我看不到任何其他分支,但我可以正确地看到历史记录(所有更改).单击任何提交时,我可以看到以下信息:

I want to convert mercurial repo to git repo. Actually I did but I didnt see branches. After I converted repo I can see just one branch(as master) I cannot see any other branches but I can see history(all changes) as right. when clicked any commits I can see like this information :

Date: 19 Nisan 2019 Cuma 15:14:37
Committer: sevgi.cakmak
Change dialog header

--HG--
branch : sevgi-2.0.0   

但我在左侧看不到 sevgi-2.0.0 分支(我使用的是 sourcetree).

but I cannot see sevgi-2.0.0 branch on the left side (I am using sourcetree).

我的步骤:

mercurial.ini 文件:

mercurial.ini file:

[extensions]
strip = 
histedit = 
rebase = 
hggit = C:Userssevgi.cakmakDesktophg-githggit
hgext.bookmarks =

[git]
intree = True

hg bookmark -r 2.0.0 master(也试过这样:hg bookmark -r default master)然后我从 cmd 处理了这条线

hg bookmark -r 2.0.0 master (also tried like this: hg bookmark -r default master) and then I worked this line from cmd

hg gexport --debug //this line converting all revision

在这一行工作后,我的输出是这样的:

after worked this line my output like this:

converting revision a318482e0769e2fceb13a1545cb477d60a00b434
converting revision e444655d161131f9ed1676f6c175813097fd18g8
converting revision 0ab06d22eaf4ff4ecb96caba343fdcc3a85e367k
converting revision 8a4e7f4defb0b04e76e67a825bedf746fe4f3fc5  ......etc

然后我处理了这一行 git config --bool core.bare false .毕竟我在 .git 下打开了分支文件夹,这个旧的是空的.我想在我的 repo 上看到分支.

and then I worked this line git config --bool core.bare false . After all I did open branches folder under the .git and this older is empty. I want to see branches on my repo.

参考:https://helgeklein.com/blog/2015/06/converting-mercurial-repositories-to-git-on-windows/

我也试过快速导出但没有用.

also I tried fast-export but didnt work.

推荐答案

来自 docs section用法:

Hg-Git 将您的书签作为分支推送到 Git 服务器,并将拉下 Git 分支并将它们设置为书签.

Hg-Git pushes your bookmarks up to the Git server as branches and will pull Git branches down and set them up as bookmarks.

...

配置

...

git.branch_bookmark_suffix

hg-git 不会在 Mercurial 命名分支和 git 之间转换分支,因为两者在概念上是不同的;相反,它使用Mercurial 书签代表 git 分支的概念.因此,在将 hg repo 转换为 git 时,您通常需要创建书签以反映您想要的所有命名分支把看到的转移到git.与此有关的主要警告是您不能为您的书签使用与命名分支相同的名称,此外,没有可行的方法来重命名分支水银.

hg-git does not convert between Mercurial named branches and git branches as the two are conceptually different; instead, it uses Mercurial bookmarks to represent the concept of a git branch. Therefore, when translating an hg repo over to git, you typically need to create bookmarks to mirror all the named branches that you'd like to see transferred over to git. The major caveat with this is that you can't use the same name for your bookmark as that of the named branch, and furthermore there's no feasible way to rename a branch in Mercurial.

对于想要将 hg 回购转移到的用例git,并维护与 hg 上相同的命名分支另一方面,branch_bookmark_suffix 可能就是所需要的.这个显示将在每个书签上识别的字符串后缀"名称,并在书签转换为 git 分支时被删除:

For the use case where one would like to transfer an hg repo over to git, and maintain the same named branches as are present on the hg side, the branch_bookmark_suffix might be all that's needed. This presents a string "suffix" that will be recognized on each bookmark name, and stripped off as the bookmark is translated to a git branch:

[git]
branch_bookmark_suffix=_bookmark

以上,如果一个 hg repo 有一个名为的分支release_6_maintenance,然后您可以将其链接到名为的书签release_6_maintenance_bookmark.hg-git 然后将剥离_bookmark 后缀从此书签名称,并创建一个git分支称为 release_6_maintenance.当从 git 拉回 hg 时,_bookmark 后缀被应用回来,当且仅当一个名为 hg存在该名称的分支.例如,当更改为release_6_maintenance 分支被检入 git,这些将是放在 hg 上的 release_6_maintenance_bookmark 书签中.但如果一个名为 release_7_maintenance 的新分支被拉到 hg,并且还没有 release_7_maintenance 命名分支,书签将被命名为 release_7_maintenance,不使用后缀.

Above, if an hg repo had a named branch called release_6_maintenance, you could then link it to a bookmark called release_6_maintenance_bookmark. hg-git will then strip off the _bookmark suffix from this bookmark name, and create a git branch called release_6_maintenance. When pulling back from git to hg, the _bookmark suffix is then applied back, if and only if an hg named branch of that name exists. E.g., when changes to the release_6_maintenance branch are checked into git, these will be placed into the release_6_maintenance_bookmark bookmark on hg. But if a new branch called release_7_maintenance were pulled over to hg, and there was not a release_7_maintenance named branch already, the bookmark will be named release_7_maintenance with no usage of the suffix.

branch_bookmark_suffix 选项与作者选项一样,用于迁移遗留的 hg 命名分支.前进,汞与 git repo 链接的 repo 应该只使用书签用于命名分支.

The branch_bookmark_suffix option is, like the authors option, intended for migrating legacy hg named branches. Going forward, an hg repo that is to be linked with a git repo should only use bookmarks for named branching.

这篇关于如何在不丢失分支的情况下将 mercurial 存储库转换为 git 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆