2010-07-09 34 views
4

我主要使用Git工作,並在github上有很多代碼。我也想在Bitbucket上使用它,因爲使用mercurial的人更重要,因爲我想在我的domian上也有代碼,並且BItbucket支持託管代碼的Cname。Meritial的Git橋

所以有一種方式讓我主要使用Git,但也能推到HG。 Github在其他方向創建了一個項目(對於HG回購git),但是有一個針對我正在尋找的方向。

+2

hg-git是雙向的。 – 2010-07-10 12:56:10

+0

[Git與Mercurial Repository互操作性]的可能重複(http://stackoverflow.com/questions/883452/git-interoperability-with-a-mercurial-repository) – skolima 2011-07-20 11:32:44

回答

4

如果你只是在做的Git回購(S)的一面鏡子,那麼你可以設置一個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你的工作,那麼就沒有關係。

7

我打算把這個添加到我的其他答案中,但它有點長,所以我們將它作爲一個單獨的答案。

如果您想要兩種方式,您可以使用hg-git在您的機器上獲得hg版本的回購。你仍然可以在Git中完成所有的工作,這意味着你將使用GitHub作爲你的中介。

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

然而,它確實有,如果你想拉從水銀用戶的變化,你可以拉他們到hg回購,並推動他們去GitHub上的好處。

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