Asleep from Day

August 27, 2008

git clone –mirror

Filed under: scm — John @ 6:39 pm

It seems there will be a new option for git-clone, ‘–mirror’. The command line

$ git clone --mirror $URL

is now a short-hand for

$ git clone --bare $URL
$ (cd $(basename $URL) && git remote add --mirror origin $URL)

Refer to http://kerneltrap.org/mailarchive/git/2008/8/2/2793244 about this.

This is extremely useful if you need to check the contents of different branches in different directories at the same time. Each directory will be a local git clone -l -s, and git push will use –mirror as well by default.

June 5, 2008

git first, git-svn later.

Filed under: scm — John @ 5:18 pm

the whole story is that I started a project locally and I used git as my SCM. now I’m going to put it into a svn repository with full history but I still want to use git.

normally you should make this decision at the beginning. that means you
git-svn clone http://svn.somewhere.com/myproject
first, then you use git as usual, do git-svn rebase and git-svn dcommit. you have to do this because git-svn must know where to start, namely you should have at least one git-svn-id in your git log to start with.

here is how I add svn support into an existing git repository. basically it’s easy, you just
git-svn init http://svn.somewhere.com/myproject
git-svn fetch

now git branch -r should tell you there is a branch called git-svn. you git rebase git-svn your current master. if it succeeded then you’re all set.

however, in order to do this, there must be a point back in time that these two branches are the same. if it’s not the case, you’re in trouble. you have to use git-svn set-tree to force a svn commit to be your starting point. in my case, the svn repository started out empty, so I forced the first commit in my git. after that git rebase succeeded like I expected.

March 24, 2008

git-svn

Filed under: scm — John @ 6:14 pm

像 subversion (svn) 這類集中式的 scm 一定要有網路連線才能 commit ,這是很討厭的一件事情,尤其是很多人都會用 notebook 工作,不見得需要長時間連結網路,或者是並沒興趣修改 svn 上的版本。這時候像老牌的 monotone 或是現在的 git 以及 Mercurial 這種分散式的版本管理系統就很好用。這陣子在改一個 project,他已經有 svn 在 googlecode 上,看來已經很久沒人 maintain. 我當然還不需要 svn write 權限,但是我仍然希望在自己 local 端有版本管理,這樣我如果幹了什麼蠢事才救得回來。

此時 git-svn 這種工具就真的很好用。基本使用方式是

# Clone a repo (like git clone):
        git-svn clone http://svn.foo.org/project/trunk
# Enter the newly cloned directory:
        cd trunk
# You should be on master branch, double-check with git-branch
        git branch
# Do some work and commit locally to git:
        git commit ...
# Something is committed to SVN, rebase your local changes against the
# latest changes in SVN:
        git-svn rebase
# Now commit your changes (that were committed previously using git) to SVN,
# as well as automatically updating your working HEAD:
        git-svn dcommit
# Append svn:ignore settings to the default git exclude file:
        git-svn show-ignore >> .git/info/exclude

日後如果我想要把修改 commit 到 upstream 去,我在這段時間的修改記錄仍然可以保留。相當有彈性的作法。

Blog at WordPress.com.