将HG版本库推送到Git服务器

如何将HG版本库推送到Git服务器?

目的

习惯使用HG来进行版本管理,但是GitHub代码统计比Bitbucket要丰富,所以准备主力仓库选用Bitbucket,GitHub作为备用仓库.

GitHub本身不支持 HG 版本库,所以需要用到HG-Git扩展插件来实现转义或翻译Git类型的版本库.

参考资料

  1. 9. Use with other VCS systems — TortoiseHg 3.8.0 documentation

  2. Hg-Git Mercurial Plugin

  3. durin42 / hg-git — Bitbucket

  4. Set up an SSH key - Atlassian Documentation

TortoiseHg 启用 HG-Git 的方法

Windows 版本的 TortoiseHg 已经集成了 HG-Git 扩展插件 (及其必备运行环境 Dulwich) ,因此只需要在 .hgrc 配置文件里设置一下即可启动.

[extensions]
hggit =

填坑记录

几种 Git 仓库地址的区别

  1. https://github.com/schacon/hg-git.git

    权限支持:可读 可写.
    GitHub 内建的克隆方式.

    HG-Git 支持.

    使用此格式的地址克隆仓库时会出错提示:
    中止: No module named selectors!

  2. git@github.com:schacon/hg-git.git

    权限支持:可读 可写.
    GitHub 内建的克隆方式. 需要 SSH key 和 passphrase.

    HG-Git 支持.

    使用此格式的地址克隆仓库时会出错提示:
    系统找不到指定的路径。中止: git remote error: The remote server unexpectedly closed the connection.

  3. git://github.com/schacon/hg-git.git

    权限支持:

    HG-Git 支持通过此格式 克隆仓库 到本地.

    但是一旦推送本地修改到服务器,就会报错git remote error: You can't push to git://.git Use https://.git
    参考资料:

    1. fatal: remote error: You can't push to git (Example)
    2. Git Bash: remote error: You can't push to git://github.com/ - Stack Overflow
  4. git+ssh://git@github.com/schacon/hg-git.git

    以下引用自:durin42 / hg-git - Usage — Bitbucket

    If you want to clone a github repository for later pushing (or any other repository you access via ssh), you need to convert the ssh url to a format with an explicit protocol prefix.

    For example, the git url with push access

       git@github.com:schacon/hg-git.git
    

    would read

       git+ssh://git@github.com/schacon/hg-git.git
    

    (Mind the switch from colon to slash after the host!)

    翻译如下:

    假如需要克隆一个支持后续推送的仓库,
    那么就需要将 SSH URL 转换为一种特定的协议前缀(git+ssh://)的格式.

    例如原地址为
    git@github.com:schacon/hg-git.git

    需要转换为
    git+ssh://git@github.com/schacon/hg-git.git

    注意原地址域名后面的冒号之后的部分需要特别留意.

如何推送修改到一个现成的 Git 仓库?

  1. 得到目标 Git 仓库的 SSH 地址

    例如: git@github.com:schacon/hg-git.git

  2. 将其转换为特定的格式

    例如: git+ssh://git@github.com/schacon/hg-git.git

  3. 生成 SSH 私钥公钥

    在线的方式生成(不用安装特殊软件):

    1. Free Online Private and Public Key Generator
    2. Online RSA Key Generator
    3. ONLINE Generate ssh RSA key,public key,private key,generate ssh pair
    4. Online Generate SSH keys algorithm RSA,DSA,ECDSA

    通过软件生成:

    1. TortoiseGit生成.PPK拓展名的密钥 - CSDN博客
    2. liunx----putty--ssh--ppk---密文自动登陆 - CSDN博客
    3. How to use ssh-keygen to generate a new SSH key | SSH.COM
    4. Using PuTTYgen on Windows to generate SSH key pairs | SSH.COM
  4. 将公钥添加到GitHub

  5. 将私钥转换为*.PPK格式

    1. Convert SSH private key with PuTTY keygen : Some tutorials and articles
    2. linux私钥id_rsa转换成ppk - CSDN博客
    3. Site5 KnowledgeBase » SSH: Convert SSH Keys to PPK Format
    4. How to convert PuTTY's .ppk to SSH key
    5. Converting OpenSSH and PuTTY Style Keys
    6. Use SSH Keys with PuTTY on Windows | ProfitBricks DevOps Central
  6. 修改配置文件

    [ui]
    username = AsionTang
    ssh = "D:\TortoisePlink.exe" -ssh -2 -C -i "D:\ye.github.ppk"
    
  7. 接受并缓存GitHub的Host Key

如何克隆一个现成的 Git 仓库到本地?

找到正确的 Git 仓库地址
例如 https://github.com/schacon/hg-git
将其修改为 git://github.com/schacon/hg-git.git 一样格式的地址,正常克隆即可.

SSH 连接时出现错误Unable to use key file "id_ras" (OpenSSH SSH-2 private key (old PEM format))

将PEM私钥格式转换为*.PPK格式即可.

SSH 连接时出现错误Server refused our key

将仓库地址从 git+ssh://github.com/schacon/hg-git.git 改为 git+ssh://git@github.com/schacon/hg-git.git 后解决此问题. 在域名前多了个用户名 git@

附件列表

     

    posted @ 2018-07-19 17:13  Asion Tang  阅读(1243)  评论(0编辑  收藏  举报