git-p4 迁移不同子目录下的分支

标签 git branch perforce git-p4

我想将源代码树从 perforce 迁移到 git。源代码包含几个分散在 perforce depot 中的开发分支,不一定在同一个目录中。例如结构是这样的 -

//depot/dev/project/master 
//depot/dev/project/branch1 
//depot/dev/project/branch2
//depot/dev/sub-project/branch3 
//depot/dev/sub-project/branch4 
//depot/patch-project/branch5 
//depot/patch-project/special/developern/branch6 

我查看了 git-p4 文档 https://git-scm.com/docs/git-p4分支检测部分和类似文章http://forums.perforce.com/index.php?/topic/1395-git-p4-and-multiple-branches/ .

我能够为那些在直系父级下的分支迁移具有历史记录的分支

 //depot/dev/project/branch1 and 
 //depot/dev/project/branch2 

我无法实现的是如何一次将所有六个分支一起迁移。

我尝试在指定分支规范后在//depot@all level 上运行迁移,但是它失败了,因为 perforce 服务器很大,它给出了 maxresults 异常或 session 超时。有人可以指导如何处理这种情况吗?

我看到的另一种选择是分别迁移分支(一个分支到一个 git 仓库),然后将所有分支 merge 到一个新的 git 仓库中。我不确定这样做是否会产生影响/不利影响。

Thanks and Regards,
Amar Kumbhar.

最佳答案

总结: 它有效,git-p4 是一个很棒的工具,非常智能,带有很多可配置选项。分散在仓库树中任何地方的多个分支已成功迁移。我们需要在涵盖所有子目录或感兴趣分支的最高级别(最顶层)perforce 目录中运行导入。为了高效操作,建议使用 --changesfile 选项,明确指定要导入的变更列表。还可以使用 git-p4.branchUsergit-p4.branchList 明确指定分支规范。

详细信息:这里我展示了对我有用的设置。可能有更好的方法来实现目标。

Perforce depot 结构:(如问题所述)

Perforce 客户端: 这设置在最高(最顶层)p4 目录中。这非常重要,否则 git-p4 可能会将更改列表(由于客户端 View 而受到限制)排除为空提交。

   //depot/... //myp4client/...

Perforce branchspecs:我创建了一个涵盖我所有分支依赖(父/子)信息的 branchspec

$ p4 branch -o test1 | grep "//"

    //depot/dev/project/master/... //depot/dev/project/branch1/...
    //depot/dev/project/master/... //depot/dev/project/branch2/...
    //depot/dev/project/branch1/... //depot/dev/sub-project/branch3/...
    //depot/dev/project/branch1/... //depot/dev/sub-project/branch4/...
    //depot/dev/project/master/... //depot/patch-project/branch5/...
    //depot/patch-project/branch5/... //depot/patch-project/special/developern/branch6

git-p4 配置项:接下来,我设置一个空的 git 存储库和以下配置项。

 mkdir workdir
 cd workdir
 git init

(**强制变量)

git config git-p4.user myp4user
git config git-p4.passwowrd myp4password
git config git-p4.port myp4port
git config git-p4.client myp4client

(** 强制使用 perforce 客户端规范)

git config git-p4.useClientSpec true
git config git-p4.client myp4client

( ** 限制探索仅由我创建的分支规范)

git config git-p4.branchUser myp4user

( ** 分支信息,依赖关系,有趣的是只需要提及姓氏(分支路径中的目录名),git-p4 自动检测/选择所需的内容,即完全扩展分支名称)

git config git-p4.branchList master:branch1
git config --add git-p4.branchList master:branch2
git config --add git-p4.branchList branch1:branch3
git config --add git-p4.branchList branch1:branch4
git config --add git-p4.branchList master:branch5
git config --add git-p4.branchList branch5:branch6

更改列表文件:接下来,我为我要迁移的所有分支收集了所有更改列表。

p4 changes //depot/dev/project/master/...  | cut -d' ' -f2 >> master.txt
p4 changes //depot/dev/project/branch1/...  | cut -d' ' -f2 >> master.txt
p4 changes //depot/dev/project/branch2/...  | cut -d' ' -f2 >> master.txt
p4 changes //depot/dev/sub-project/branch3/...  | cut -d' ' -f2 >> master.txt
p4 changes //depot/dev/sub-project/branch4/...  | cut -d' ' -f2 >> master.txt
p4 changes //depot/patch-project/branch5/...  | cut -d' ' -f2 >> master.txt
p4 changes //depot/patch-project/special/developern/branch6/...  | cut -d' ' -f2 >> master.txt

sort -n master.txt | uniq > master_sorted.txt

导入:最后我按如下方式运行导入,我使用的是“同步”而不是克隆。

cd workdir 
../git-p4.py sync //depot/... --detect-branches --verbose --changesfile /home/myp4user/master_sorted.txt

在较小的 depot 上“../git-p4.py sync//depot@all --detect-branches --verbose “也应该有效,在这种情况下不需要创建变更列表文件(前面的步骤)

导入完成后,我可以看到 git-p4 在单个 git 存储库中创建了所有远程 perforce 分支。

 git branch -a
  remotes/p4/depot/dev/project/master
  remotes/p4/depot/dev/project/branch1
  remotes/p4/depot/dev/dev/project/branch2
  remotes/p4/depot/dev/dev/sub-project/branch3
  remotes/p4/depot/dev/dev/sub-project/branch4
  remotes/p4/depot/patch-project/branch5
  remotes/p4/depot/patch-project/special/developern/branch6

然后我从远程 p4 分支创建了本地分支

  git checkout -b master  remotes/p4/depot/dev/project/master
  git checkout -b branch1  remotes/p4/depot/dev/project/branch1
  git checkout -b branch2   remotes/p4/depot/dev/dev/project/branch2
  git checkout -b branch3   remotes/p4/depot/dev/dev/sub-project/branch3
  git checkout -b branch4   remotes/p4/depot/dev/dev/sub-project/branch4
  git checkout -b branch5   remotes/p4/depot/patch-project/branch5
  git checkout -b branch6   remotes/p4/depot/patch-project/special/developern/branch6

接下来我简单地添加了一个远程源并将代码推送到 git repo 中。
感谢 stackoverflow 和在线提供的各种指示/帮助。

关于git-p4 迁移不同子目录下的分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37607393/

相关文章:

svn - 在 SVN 中基于没有 trunk 目录的项目创建新分支的最佳实践是什么?

perforce - 如何在不修改本地文件的情况下取消跟踪 Perforce 更改列表中的更改(P4V 2015.2)?

perforce - p4 恢复后删除新文件

git - Composer 更新 - 没有获得最新版本

git - 清理远程 Git 分支

git - 为什么在任何地方都没有 git credential-osxkeychain 的文档?

svn - 在SVN中从trunk的子文件夹创建分支会有什么后果?

c++ - 构建 Qt 应用程序时如何运行 git 命令

git - GIT 的名称不明确?

perforce - 在退出之前困惑的集成后,无法从主分支完全集成到功能分支