54 CHEN

Git Svn使用手记

git

以下是一个淡疼的记录,因为从linkedin归来的宝秋叔大力推荐git,而我们现在的代码大多在svn中,所以就有了这一段故事。

一、同步回来svn

$git svn clone https://miliaocode/repos/project -T trunk -b branches -t tags

然后进入漫长的等待。
-T trunk -b branches -t tags 告诉 Git 该 Subversion 仓库遵循了基本的分支和标签命名法则。如果你的目录下没有三个标准目录的话还是不要加了。

二、完成同步之后

localhost:xxx chenzhen$ git branch -a
* master
remotes/git-svn
localhost:xxx chenzhen$ git show-ref
ecf28daf78732c0538a99e206bd9e6e32cbd1ff3 refs/heads/master
ecf28daf78732c0538a99e206bd9e6e32cbd1ff3 refs/remotes/git-svn

远程的svn只作为一个远程的分支存在。

三、使用 $cd xxx
$vim yyy
$git commit -am ‘Adding git-svn instructions to the README’
这一步是提交到本地,还可以用各种分支之类的都是对本地的操作。

四、注意 $git svn rebase
这一步应该经常被执行,防止出现空洞,因为svn会在服务器端进行merge。而git却不会。
避免使用merge和直接提交,多rebase后再提交。
和svn关联的分支能不用则不用。

五、提交 $git svn dcommit

六、文件忽略 一些忽略文件在svn中是有的,而git中会有一个文件在记录它。
$git svn show-ignore
$git svn create-ignore
第二条命令会创建.gitignore文件,但这对于 svn用户来说太难看了。于是可以如下操作:

$ git svn show-ignore > .git/info/exclude

七、剩下 剩下的就是git的事情了,你在本地怎么玩,怎么开源,怎么发远程的,不再影响内部svn用户了。

11月20日补充内容:

八、git merge工具设置 到http://www.perforce.com/perforce/downloads/component.html下载并安装p4merge工具(比较好用的双窗口diff工具)。
建立一个merge命令调用它:
$sudo vim /usr/bin/extMerge

#!/bin/sh
/Applications/p4merge.app/Contents/MacOS/p4merge $*
$sudo chmod +x /usr/bin/extMerge

修改~/.gitconfig文件:

[merge]
tool = extMerge
[merge “tool”]
cmd = extMerge \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"
[mergetool]
trustExitCode = false

这样就可以在rebase的时候自动弹出来merge工具进行修改。

九、与review board发code review的协作 当完成代码的编写后,可以在本地招行git commit -am ‘some thing’,然后需要发code review的话,就需要一段脚本来帮忙了。

http://mojodna.net/2009/02/24/my-work-git-workflow.html 这哥们写了一份,在mac下的有些格式需要调整。Baoqiu更新了源码,我们米的同学可以来信索取最新的代码。

此脚本为git-svn-diff,放在/usr/bin下之后chmod +x /usr/bin/git-svn-diff。

修改~/.gitconfig,添加如下内容:

[alias]
svn-diff = !git-svn-diff

然后就可以用了,

$git svn-diff > patch

十、git命令的自动完成 如果你是用的xcode里的git,那可能自动完成是不能使用的,你可以自己试试git ch,如果有提示的放忽略本节。
如果没有,vim ~/.profile添加:

source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash

原创文章如转载,请注明:转载自五四陈科学院[http://www.54chen.com]

捐赠说明

Posted by 54chen linux

« qcon杭州2012读后感 企业github之高仿选择-gitlab使用实录 »