Git 与 Mercurial 的桥梁

发布于 2024-09-09 07:04:24 字数 238 浏览 9 评论 0原文

我主要使用 Git,并且在 github 上有很多代码。我也希望将其放在 Bitbucket 上,供使用 Mercurial 的人使用,但更重要的是,因为我也希望将代码放在我的 domian 上,并且 BItbucket 支持托管代码的 Cname。

那么有没有一种方法可以让我主要使用 Git,同时也能够推送到 HG。

Github 在其他方向创建了一个项目(对于 HG 存储库到 git),但是有一个适合我正在寻找的方向吗?

I work mostly with Git and have a lot of code on github. I would also like to have it on Bitbucket, for people using mercurial but more importantly as I want to also have the code on my domian, and BItbucket supports Cnames for hosted code.

So is there a way for me to mostly work with Git, but also be able to push to HG.

Github created a project in other direction, (For HG repos to git), but is there one for the direction I am looking for.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有伤那来痛 2024-09-16 07:04:24

我本来打算将其添加到我的其他答案中,但它有点长,所以我们将其作为单独的答案。

如果您想双向使用,可以使用 hg-git 获取 hg您计算机上的存储库版本。您仍然可以在 Git 中完成所有工作,这只是意味着您将使用 GitHub 作为您的中介。

$ cd src
# do some work
# push to GitHub
$ cd ../hg
$ hg pull
$ hg push bitbucket

然而,它确实有一个好处,如果您想从 Mercurial 用户那里提取更改,您可以将它们拉入 hg 存储库,然后将它们推送到 GitHub。

$ cd hg
$ hg pull someotherrepo
  # Probably merge
$ hg push # Changes go to GitHub
$ cd ../src
$ git pull
  # Continue working in Git

I was going to add this to my other answer, but it got a little long, so we'll do it as a separate answer.

If you want to go both ways, you can use hg-git to get an hg version of the repo on your machine. You can still do all of your work in Git, it just means you'll be using GitHub as your intermediary.

$ cd src
# do some work
# push to GitHub
$ cd ../hg
$ hg pull
$ hg push bitbucket

However, it does have the benefit that if you want to pull changes from a Mercurial user, you can pull them into the hg repo, and push them out to GitHub.

$ cd hg
$ hg pull someotherrepo
  # Probably merge
$ hg push # Changes go to GitHub
$ cd ../src
$ git pull
  # Continue working in Git
来日方长 2024-09-16 07:04:24

如果您只是做 Git 存储库的镜像,那么您可以设置一个 cron 作业来运行以下脚本:

#!/bin/bash

USER=bitbucketuser
ERROR_FILE=clone_update_err
CLONES=/path/to/clones

cd $CLONES

if [ $# -ne 1 ]; then
    for DIR in *; do
        if [ -d $DIR ]; then
            ./update.sh $DIR 2> $ERROR_FILE
            if [ -s $ERROR_FILE ]; then
                echo $DIR >&2
                cat -n $ERROR_FILE >&2
            fi
        fi
    done
else
    DIR=$1
    echo $DIR
    cd $DIR

    if [ -a source ]; then
        cd source
        if [ -d .hg ]; then
            hg pull
        elif [ -d .git ]; then
            git pull
        elif [ -d .bzr ]; then
            bzr pull
        elif [ -d .svn ]; then
            svn up
        else
            echo "$DIR is not a known repository type."
            return 1
        fi

        cd ..
        hg convert source hg

        URL=ssh://[email protected]/$USER/$DIR/
        cd hg
        hg pull $URL
        hg push $URL # You can add -f here if you don't mind multiple heads
        cd ..
    else
        # hg dir or hg-git
        cd hg
        hg pull
        hg push $URL
        cd ..
    fi

    cd ..

    sleep 5
fi

这假设您安装了 SSH 密钥。正如您所看到的,它也会镜像其他 VCS。它假定这样的目录结构:

clones/
  project1/
    source/  # Original Git/Bazaar/SVN/Mercurial repo
    hg/      # Mercurial repo

显然,这只是单向的,但如果您在 Git 中完成所有工作,那么这并不重要。

If you're just doing a mirror of the Git repo(s), then you can set up a cron job to run the following script:

#!/bin/bash

USER=bitbucketuser
ERROR_FILE=clone_update_err
CLONES=/path/to/clones

cd $CLONES

if [ $# -ne 1 ]; then
    for DIR in *; do
        if [ -d $DIR ]; then
            ./update.sh $DIR 2> $ERROR_FILE
            if [ -s $ERROR_FILE ]; then
                echo $DIR >&2
                cat -n $ERROR_FILE >&2
            fi
        fi
    done
else
    DIR=$1
    echo $DIR
    cd $DIR

    if [ -a source ]; then
        cd source
        if [ -d .hg ]; then
            hg pull
        elif [ -d .git ]; then
            git pull
        elif [ -d .bzr ]; then
            bzr pull
        elif [ -d .svn ]; then
            svn up
        else
            echo "$DIR is not a known repository type."
            return 1
        fi

        cd ..
        hg convert source hg

        URL=ssh://[email protected]/$USER/$DIR/
        cd hg
        hg pull $URL
        hg push $URL # You can add -f here if you don't mind multiple heads
        cd ..
    else
        # hg dir or hg-git
        cd hg
        hg pull
        hg push $URL
        cd ..
    fi

    cd ..

    sleep 5
fi

This assumes you have an SSH key installed. As you can see, it will mirror other VCSs as well. It assumes a directory structure like this:

clones/
  project1/
    source/  # Original Git/Bazaar/SVN/Mercurial repo
    hg/      # Mercurial repo

Obviously, this is only one-way, but if you do all of your work in Git, then it won't matter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文