顯示具有 git 標籤的文章。 顯示所有文章
顯示具有 git 標籤的文章。 顯示所有文章

2017年11月17日 星期五

git clone hg repository and vice versa

希望大家不會遇到像我這樣的問題, 我很喜歡 git, 希望世界上只剩下 git, 但這是不可能的, rcs, cvs, svn, mercurial 還有很多沒聽過得版本控制軟體都存在世界上。

由於需要使用 mercurial, 我實在用不慣, 找到了可以用 git clone mercurial repository 的方法。需要安裝 git-remote-hg。
git clone hg repository:
Bridge support in git for mercurial and bazaar
https://felipec.wordpress.com/2012/11/13/git-remote-hg-bzr-2/

apt-get install git-remote-hg

git clone "hg::http://username:password@a.b.com/x/y/z"
就這麼簡單, 沒了。
不過在操作 git push 時失敗了, 出現

TypeError: getchangegroup() got an unexpected keyword argument 'heads'
參考了 https://github.com/felipec/git-remote-hg/issues/66
但是搞不定。


另外一個作法:
git-cinnabar

apt-get install python-requests

git clone https://github.com/glandium/git-cinnabar.git
將 clone 的目錄加入 PATH
ex:
export PATH=/home/descent/git/git-cinnabar:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games

git cinnabar download
make helper

一樣的 clone hg repository 指令:
git clone "hg::http://username:password@a.b.com/x/y/z"
git push 正常。



我體會到一樣的痛苦, 反過來照顧一下需要用 hg clone git repository 的使用者。

hg clone git repository:

apt-get install python-dulwich python-dev
easy_install hg-git

編輯 ~/.hgrc:

[extensions]
hgext.bookmarks =
hggit = 

clone git ssh repository
hg clone git+ssh://username@ip_or_domain_name/a_dir/b_dir/u-boot.git

舉例來說, 如果你想要 clone https://github.com/descent/simple_stdcpplib.git, 可以這樣下 hg clone 指令:
hg clone git+https://github.com/descent/simple_compiler.git

hg clone 會把 git repository branch 轉成 hg bookmark

Using TortoiseHg with Git
https://mcmblog.azurewebsites.net/using-tortoisehg-with-git/

the Hg-Git mercurial plugin

2016年2月15日 星期一

sync github 上 fork 的 repository

fork github 上的 repository 很容易, 要同步他們到最新的版本就困難多了。
官方文章在說明如何做到這件事: Syncing a fork (github)

cd your_forked_repository
git remote add upstream original_git_url

ex:
git remote add upstream https://github.com/dwelch67/raspberrypi.git

git remote -v
git fetch upstream
git checkout master
git merge upstream/master
git push

指令看不懂也沒關係, 照打就可以了, 不會破壞原本的 repository。

原理大概是這樣: 加入 fork 的那個 repository url, 取名為 upstream, 在 merge 這個 upstream 的 master branch 到自己的 master branch。

2016年1月29日 星期五

git subtree - 分割 repository 的某個目錄, 獨立成為一個 repository

git subtree 可以將 git repository 的某個目錄分割出來成為一個單獨的 repository。《simple c++ 標準程式庫》就是這樣把分散在各個 git repository 的檔案集合起來, 並保留完整的 git log。

repository path: ~/stm32_p103_demos

# 分割 ~/stm32_p103_demos/demos/uart_echo/mymap 成為一個獨立的 repository
cd ~/stm32_p103_demos
git subtree split -P demos/uart_echo/mymap -b mymap
mkdir /tmp/mymap
cd /tmp/mymap
git init
git pull ~/stm32_p103_demos mymap

# 送到遠端 repository
git remote add origin
git push origin -u master

# 刪除 ~/stm32_p103_demos/demos/uart_echo/mymap
cd ~/stm32_p103_demos
git rm -rf demos/uart_echo/mymap


ref:
Detach subdirectory into separate Git repository


2011年9月23日 星期五

clone A git/svn repo then push to B git repo

最近有個需求, 需要將 git svn clone 下來的 git repo 放到另外一個 git repo 上。我本來打算使用 google code 的 git, 但因為一直有問題, 也不知道是 google code 還是我 git 指令不熟悉的問題, 現在改放到 github 上。

git svn clone git_svn_repo
git clone github_repo
cd github_repo
git pull ~/git_svn_repo
git push origin master

git pull ~/git_svn_repo 會做類似 git fetch, 然後再自動執行 git merge, 在 git log 上, 可以看到 merge 的字樣。

終於搞定這問題了。


加入一個 remote, 然後 push 到該 remote
git remote add remotename ssh://git@r.no-ip.org:1234/~/repo/b.git/
git push remotename master

ref: http://tkg.im.ncue.edu.tw/?p=755

bitbucket 的指令:
cd /path/to/my/repo
git remote add origin ssh://git@bitbucket.org/ds/ticker.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push -u origin --tags # pushes up any tags