I'm getting started with learning subtree merging in git 1.8.2. I have created a simple example to test a change to a third party repo migrating into a main project.
I'm following the 6.7 Git Tools - Subtree Merging example.
The 'sub' project is included as a subdirectory in the 'main' project.
After I make a change to the 'sub' project, git reports a conflict when I try to merge the change into the 'main' project.
Test Summary
- Created repos for projects 'main' and 'sub' (sub instead of rack)
- Add remote named sub_remote to main that refers to sub
- Track sub_remote using sub_branch
- Change and commit one line in a file in the 'sub' project
- Pull changes from sub over to main/sub_branch
- Merge main/sub_branch into main/master.
The merge fails with a conflict. Merge is confused about which version of the changed line to keep.
<<<<<<< HEAD
main
=======
main upstream change
>>>>>>> sub_branch
main.git
sub
sub.git
tm
Complete Test Script
#!/bin/sh
# initialize empty repos
for i in main sub
do
rm -rf $i{,.git}
mkdir $i.git
cd $i.git;
git --bare init;
cd ..;
git clone $i.git
cd $i
echo $i > readme.md
git add readme.md
git commit -a -m "added readme.md"
git push origin master
cd ..
done
# add data to sub
ls > sub/data
cd sub
git add data
git commit -m "Added data"
git push origin master
cd ..
# add sub as a sub-tree in main
cd main
git remote add sub_remote ../sub.git
git fetch sub_remote
git checkout -b sub_branch sub_remote/master
git checkout master
git read-tree --prefix=sub/ -u sub_branch
git commit -m "Added sub"
git push origin master
cd ..
# make change to sub
cd sub
sed -i -e 's/main$/main upstream change/' data
git commit -a -m "upstream change made to data"
git push origin master
cd ..
# merge sub change to main
cd main
git checkout sub_branch
git pull
#merge sub_branch changes into master
git checkout master
git merge -s subtree sub_branch
cat sub/data