test.shon commit Okay, that was a little too aggressive. (96db2c0)
   1#!/bin/bash -x
   2. shellopts.sh
   3set -e
   4
   5rm -rf mainline subproj
   6mkdir mainline subproj
   7
   8cd subproj
   9git init
  10
  11touch sub1
  12git add sub1
  13git commit -m 'sub-1'
  14git branch sub1
  15git branch -m master subproj
  16
  17touch sub2
  18git add sub2
  19git commit -m 'sub-2'
  20git branch sub2
  21
  22touch sub3
  23git add sub3
  24git commit -m 'sub-3'
  25git branch sub3
  26
  27cd ../mainline
  28git init
  29touch main1
  30git add main1
  31git commit -m 'main-1'
  32git branch -m master mainline
  33
  34git fetch ../subproj sub1
  35git branch sub1 FETCH_HEAD
  36git read-tree --prefix=subdir FETCH_HEAD
  37git checkout subdir
  38tree=$(git write-tree)
  39com=$(echo initial-subdir-merge | git commit-tree $tree -p HEAD -p FETCH_HEAD)
  40git reset $com
  41#git commit -m 'initial-subdir-merge'
  42
  43git merge -m 'merge -s -ours' -s ours FETCH_HEAD
  44
  45touch subdir/main-sub3
  46git add subdir/main-sub3
  47git commit -m 'main-sub3'
  48
  49touch main-2
  50git add main-2
  51git commit -m 'main-2 boring'
  52
  53touch subdir/main-sub4
  54git add subdir/main-sub4
  55git commit -m 'main-sub4'
  56
  57git fetch ../subproj sub2
  58git branch sub2 FETCH_HEAD
  59git merge -s subtree FETCH_HEAD
  60git branch pre-split
  61
  62split1=$(git subtree split --onto FETCH_HEAD subdir --rejoin)
  63echo "split1={$split1}"
  64git branch split1 "$split1"
  65
  66touch subdir/main-sub5
  67git add subdir/main-sub5
  68git commit -m 'main-sub5'
  69
  70cd ../subproj
  71git fetch ../mainline split1
  72git branch split1 FETCH_HEAD
  73git merge FETCH_HEAD
  74
  75touch sub6
  76git add sub6
  77git commit -m 'sub6'
  78
  79cd ../mainline
  80split2=$(git subtree split subdir --rejoin)
  81git branch split2 "$split2"
  82
  83touch subdir/main-sub7
  84git add subdir/main-sub7
  85git commit -m 'main-sub7'
  86
  87split3=$(git subtree split subdir --rejoin)
  88git branch split3 "$split3"
  89
  90cd ../subproj
  91git fetch ../mainline split3
  92git branch split3 FETCH_HEAD
  93git merge FETCH_HEAD
  94git branch subproj-merge-split3
  95
  96cd ../mainline
  97git fetch ../subproj subproj-merge-split3
  98git branch subproj-merge-split3 FETCH_HEAD
  99git merge -s subtree subproj-merge-split3