git clone multiple p4 paths in one git repo

git, perforce

Solution

The solution that I found was clonning different Perforce paths into different Git repositories and later merge them into a new repository while keeping the history.

//depot/Projects/A
...
//depot/Projects/C
//depot/Projects/...

Clonning Perforce repository into git:

git p4 clone //depot/Projects/A@all
git p4 clone //depot/Projects/C@all

Then create an empty Git repository:

mkdir project
cd project
git init

Add repositories path:

git remote add -f a ../A
git remote add -f c ../C

Merge Project A:

git merge --allow-unrelated-histories a/master

Move Project A into a subdir:

mkdir dir_a
find . -maxdepth 1 -not -name ".git" -and -not -name "dir_a" -exec git mv {} dir_a/ \;

Commit changes:

git commit -m "Merge Project A"

Merge Project C:

git merge --allow-unrelated-histories c/master
mkdir dir_c
find . -maxdepth 1 -not -name ".git" -and -not -name "dir_a" -and -not -name "dir_c" -exec git mv {} dir_c/ \;
git commit -m "Merge Project C"

Using Git:

$ git --version
git version 2.14.1

Problem

I know that if I need to clone a perforce an existing p4 repository using command ``` git p4 clone //depot/path/project ``` But what if I want to multiple p4 paths into one git repo? say I have the following structure ``` //depot---/Path1----/APath/... | | | | | --/BPath/... | | ---/Path2----/CPath/... | | ---/Path3 ``` I only want to clone files under //depot/Path1/APath/ and //depot/Path2/CPath/ in my local directory ~/Desktop/mylocalRepo/ how to do it?

Original source

Related problems