Initial situation
After converting this to a single repository, the directory structure in master (or trunk) looks like this:
project1/
project2/
project3/
project4/
The structure after the first commit of the project3-production-branch
looks either like this:
project3/
Or it contains the contents of project3 directly:
.project
src/
test/
This depends on where the branch was copied from in Subversion.
In the first case, the next step can be skipped.
In both cases, all other projects were removed on the branch (you should see that in the diff of the first commit) and need to be restored, see second step.
Step 1: Rewrite branch to move all contents into subdirectory (if needed)
See example "To move the whole tree into a subdirectory" in filter-branch and execute that only on the branch, like so:
git filter-branch --index-filter \
'git ls-files -s | sed "s-\t\"*-&project3/-" |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
git update-index --index-info &&
mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' \
master..project3-production-branch
Step 2: Rewrite branch to restore other projects
In this step we want to undo the removal of the other projects in the first branch commit. This can be done using the following:
branch="project3-production-branch"
parent=`git merge-base $branch master` # or replace master with trunk if needed
paths="project1 project2 project4"
git filter-branch -f --index-filter \
"git reset -q $parent -- $paths" --tag-name-filter cat -- \
$parent..$branch
It resets the other paths to the state they were in when the branch was created, for all commits from the branch.