将 Mercurial 文件夹转换为 Git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10710250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:44:45  来源:igfitidea点击:

Converting Mercurial folder to a Git repository

gitmercurial

提问by Simone Carletti

I don't have a huge experience with Mercurial, I'm mostly a Git guy.

我对 Mercurial 没有丰富的经验,我主要是一个 Git 人。

I would love to mirror a specific Mercurial folder/file in a git Repository. What I'm actually trying to do is to export the history of a file from a Mercurial repository to Git and being able to keep this in sync with future commits.

我很想在 git 存储库中镜像特定的 Mercurial 文件夹/文件。我实际上想要做的是将文件的历史记录从 Mercurial 存储库导出到 Git,并能够使其与未来的提交保持同步。

Do you have any suggestion on how to proceed? I believe that the way to go should be to get the history of the Mercurial patch, periodically export every single commit as a patch and apply the Mercurial patches to the Git repository.

你对如何进行有什么建议吗?我认为要走的路应该是获取 Mercurial 补丁的历史记录,定期将每个提交导出为补丁并将 Mercurial 补丁应用到 Git 存储库。

回答by Yohann

On Linuxor anything with bash/shor similar, or python, try with fast export:

Linux或任何具有bash/sh或类似的,或者python,尝试使用快速导出

cd
git clone git://repo.or.cz/fast-export.git
git init git_repo
cd git_repo
~/fast-export/hg-fast-export.sh -r /path/to/old/mercurial_repo
git checkout HEAD

回答by naXa

Windows: TortoiseHG Hg-Git extension

Windows:TortoiseHG Hg-Git 扩展

Hg-Gitcan be used to convert a Mercurial repository to Git. You can use a local repository or a remote repository accessed via SSH, HTTP or HTTPS.

Hg-Git可用于将 Mercurial 存储库转换为 Git。您可以使用本地存储库或通过 SSH、HTTP 或 HTTPS 访问的远程存储库。

Example of local repositories conversion.

本地存储库转换示例。

  1. Install Hg-Git.

    • On Windows, TortoiseHgcomes with Hg-Git, though you need to enable itvia the setting tool (in extensions section)

      TortoiseHg Settings

      or manually in ~/mercurial.ini

      [extensions]
      hggit =
      
  2. Use the following commands to convert the repository:

    $ mkdir git-repo; cd git-repo; git init; cd ..
    $ cd hg-repo
    $ hg bookmarks hg
    $ hg push ../git-repo
    
  1. 安装 Hg-Git。

    • 在 Windows 上,TortoiseHg带有 Hg-Git,但您需要通过设置工具启用它(在扩展部分)

      TortoiseHg 设置

      或手动输入 ~/mercurial.ini

      [extensions]
      hggit =
      
  2. 使用以下命令转换存储库:

    $ mkdir git-repo; cd git-repo; git init; cd ..
    $ cd hg-repo
    $ hg bookmarks hg
    $ hg push ../git-repo
    

The hgbookmark is necessary to prevent problems as otherwise hg-git pushes to the currently checked out branch confusing Git. This will create a branch named hgin the Git repository. To get the changes in master use the following commands (only necessary in the first run, later just use git mergeor rebase):

hg书签是必要的,以防止问题的发生另有HG-混帐推到当前已签出分支混淆的Git。这将创建一个hg在 Git 存储库中命名的分支。要获取 master 中的更改,请使用以下命令(仅在第一次运行时需要,以后只需使用git mergerebase):

$ cd git-repo
$ git checkout -b master hg

回答by Lazy Badger

You can (from Mercurial side):

您可以(从 Mercurial 方面):

  • using Convert extensionwith --filemapoption convert part of original repo into smaller with only needed files|directories
  • with hg-git extension push stripped repo to Git
  • 使用带有选项的Convert extension--filemap将原始 repo 的一部分转换为更小,只需要文件|目录
  • 使用 hg-git 扩展将剥离的 repo 推送到 Git

or (instead of hg-git), using Mercurial bridge in Git, clone|pull repository from Git

或者(而不是 hg-git),在 Git 中使用Mercurial 桥,从 Git 克隆|拉存储库

回答by sorin

Gitify

gitify

Seems as a more modern and easy to use alternative to perform the conversion https://github.com/buchuki/gitifyhg

似乎是一种更现代且易于使用的替代方法来执行转换 https://github.com/buchuki/gitifyhg

pip install gitifyhg
git clone gitifyhg::<hgrepoaddress>
# done, you have a git repo with the entire history of the hg one

回答by Sandre

Convert a Mercurial repository to Git on Windows 10

在 Windows 10 上将 Mercurial 存储库转换为 Git

If no problem with encoding - use TortoiseHG Hg-Git extension

如果编码没有问题 - 使用 TortoiseHG Hg-Git 扩展

md new-repo && cd new-repo
git init --bare .git
cd ..\old-mercurial-repo
hg bookmark -r default master
hg push ..\new-repo
cd ..\new-repo
git config --bool core.bare false

If something wrong with encoding - use fast-export

如果编码有问题 - 使用快速导出

Install Bash

安装 Bash

Open PowerShell as Administrator and run:

以管理员身份打开 PowerShell 并运行:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

Install Ubuntu 16.04 LTS from Microsoft Store

Microsoft Store安装 Ubuntu 16.04 LTS

Open Bash and run

打开 Bash 并运行

install mercurial

安装水银

sudo -s
apt-get update
apt install mercurial

get fast-export v180317 (at the moment versions after 180317 does not work correctly)

获取快速导出 v180317(目前 180317 之后的版本无法正常工作)

cd /mnt/c/path_to_work_folder
git clone https://github.com/frej/fast-export.git
cd fast-export
git checkout tags/v180317
cd ..

convert repository

转换存储库

git init new-repo && cd new-repo
git config core.ignoreCase false && git config core.quotepath off
../fast-export/hg-fast-export.sh -r ../path_to_mercurial_repo/ --fe cp1251
git checkout master

encoding options:

编码选项:

  • -fencoding, like -f cp1251
  • --fefile name encoding like --fe cp1251
  • -f编码,如 -f cp1251
  • --fe文件名编码如 --fe cp1251

回答by Alexander Korolev

hg-git-fast-import

hg-git-fast-import

https://github.com/kilork/hg-git-fast-import

https://github.com/kilork/hg-git-fast-import

Another utility with the following features:

具有以下功能的另一个实用程序:

  1. Import of single and multiple Mercurial repositories to Git repository.
  2. Import of new revisions from previously imported Mercurial repositories to Git repository.
  3. Tags.
  4. Closed branches.
  5. Verification of the end result with diff.
  1. 将单个和多个 Mercurial 存储库导入 Git 存储库。
  2. 将以前导入的 Mercurial 存储库中的新修订版导入 Git 存储库。
  3. 标签。
  4. 关闭的分支。
  5. 使用 diff 验证最终结果。

You may download binary for you platformand put somewhere in path or install with cargo(require rustto be installed):

您可以下载二进制为你的平台和路径放在什么地方,或者与安装cargo(需要rust进行安装):

cargo install hg-git-fast-import

Then usage is like this:

然后用法是这样的:

hg-git-fast-import single /path/to/source_hg /path/to/target_git

It does not need Pythonand Mercurialto be installed. Advanced configuration allows to replace authors or branches, make branches prefixed and more.

它不需要PythonMercurial安装。高级配置允许替换作者或分支,使分支具有前缀等等。

回答by Brad Turek

If you're using github.com, they appear to have an import featurethat lets you simply type in the URL of your hg project.

如果您使用的是github.com,它们似乎具有导入功能,您只需输入 hg 项目的 URL。

First create a new repositoryand then on the new repository's landing page scroll to the bottom and click the "Import code" button.

首先创建一个新存储库,然后在新存储库的登录页面上滚动到底部并单击“导入代码”按钮

context for the import code button

导入代码按钮的上下文

Then type the URL of your previous repositoryand hit "Begin import".

然后输入您之前存储库URL并点击“开始导入”。

context for "Begin import" button

“开始导入”按钮的上下文

Then GitHub takes care of the rest!

然后 GitHub 会处理剩下的事情!

Github taking care of business for you

Github 为您处理业务

Note that GitHub will ask you for your credentials for the old repository if it needs them.

请注意,如果需要,GitHub 会要求您提供旧存储库的凭据。

Ooh! I found the official guide

哦!我找到了官方指南

回答by slk

Maybe it helps someone today (when converting a mercurial repository to git, while retaining history). Tested to work with mercurial 4.0.1.

也许它今天对某人有所帮助(将 mercurial 存储库转换为 git,同时保留历史记录)。经测试可与 mercurial 4.0.1 一起使用。

~$ git clone https://*old_hg_repo*
~$ git clone https://github.com/frej/fast-export.git
~$ cd fast-export
~$ git checkout tags/v180317
~$ cd ..
~$ mkdir new_git_repo
~$ cd new_git_repo
~$ git init
~$ .../fast-export/hg-fast-export.sh -r ../old_hg_repo/ --force
~$ git checkout HEAD

And finally to push your newly converted local repo.

最后推送你新转换的本地仓库。

~$ git push REMOTE '*:*'

回答by Ivasan

On Windows can be a bit tricky. After enabling the right plugins in mercurial( hggit), the TortoiseHG can also be used.

在 Windows 上可能有点棘手。在 mercurial( hggit) 中启用正确的插件后,也可以使用 TortoiseHG。

  1. Clone mercurial repo
  2. Clone git repo
  3. Enable console : Enabling console
  4. Using the console :

    % hg bookmarks hg

    % hg push <relative path to>/<git-repo>

  1. 克隆 mercurial 回购
  2. 克隆 git repo
  3. 启用控制台: 启用控制台
  4. 使用控制台:

    % hg bookmarks hg

    % hg push <relative path to>/<git-repo>