Git Perforce 系统

你将了解到的下一个被导入的系统是 Perforce. Git 发行的时候同时也附带了一个 Perforce 导入脚本,不过它是包含在源码的 contrib 部分——而不像 git svn 那样默认可用。运行它之前必须获取 Git 的源码,可以在 git.kernel.org 下载:

$ git clone git://git.kernel.org/pub/scm/git/git.git
$ cd git/contrib/fast-import[/code]
 
在这个 fast-import 目录下,应该有一个叫做 git-p4 的 Python 可执行脚本。主机上必须装有 Python 和 p4 工具该导入才能正常进行。例如,你要从 Perforce 公共代码仓库(译注: Perforce Public Depot,Perforce 官方提供的代码寄存服务)导入 Jam 工程。为了设定客户端,我们要把 P4PORT 环境变量 export 到 Perforce 仓库:
[code]$ export P4PORT=public.perforce.com:1666[/code]
 
运行 git-p4 clone 命令将从 Perforce 服务器导入 Jam 项目,我们需要给出仓库和项目的路径以及导入的目标路径:
[code]$ git-p4 clone //public/jam/src@all /opt/p4import
Importing from //public/jam/src@all into /opt/p4import
Reinitialized existing Git repository in /opt/p4import/.git/
Import destination: refs/remotes/p4/master
Importing revision 4409 (100%)[/code]
 
现在去 /opt/p4import 目录运行一下 git log ,就能看到导入的成果:
[code]$ git log -2
commit 1fd4ec126171790efd2db83548b85b1bbbc07dc2
Author: Perforce staff <[email protected]>
Date:   Thu Aug 19 10:18:45 2004 -0800
 
    Drop 'rc3' moniker of jam-2.5.  Folded rc2 and rc3 RELNOTES into
    the main part of the document.  Built new tar/zip balls.
 
    Only 16 months later.
 
    [git-p4: depot-paths = "//public/jam/src/": change = 4409]
 
commit ca8870db541a23ed867f38847eda65bf4363371d
Author: Richard Geiger <[email protected]>
Date:   Tue Apr 22 20:51:34 2003 -0800
 
    Update derived jamgram.c
 
    [git-p4: depot-paths = "//public/jam/src/": change = 3108][/code]
 
每一个 commit 里都有一个 git-p4 标识符。这个标识符可以保留,以防以后需要引用 Perforce 的修改版本号。然而,如果想删除这些标识符,现在正是时候——在开启新仓库之前。可以通过 git filter-branch 来批量删除这些标识符:
[code]$ git filter-branch --msg-filter '
        sed -e "/^\[git-p4:/d"
'
Rewrite 1fd4ec126171790efd2db83548b85b1bbbc07dc2 (123/123)
Ref 'refs/heads/master' was rewritten[/code]
 
现在运行一下 git log,你会发现这些 commit 的 SHA-1 校验值都发生了改变,而那些 git-p4 字串则从提交信息里消失了:
[code]$ git log -2
commit 10a16d60cffca14d454a15c6164378f4082bc5b0
Author: Perforce staff <[email protected]>
Date:   Thu Aug 19 10:18:45 2004 -0800
 
    Drop 'rc3' moniker of jam-2.5.  Folded rc2 and rc3 RELNOTES into
    the main part of the document.  Built new tar/zip balls.
 
    Only 16 months later.
 
commit 2b6c6db311dd76c34c66ec1c40a49405e6b527b2
Author: Richard Geiger <[email protected]>
Date:   Tue Apr 22 20:51:34 2003 -0800
 
    Update derived jamgram.c

至此导入已经完成,可以开始向新的 Git 服务器推送了。

REF:http://cwiki.ossez.com/pages/viewpage.action?pageId=7045946