git merge - Git Subtree Merging reports conflict when merging a simple upstream change -
i'm getting started learning subtree merging in git 1.8.2. have created simple example test change third party repo migrating main project.
i'm following 6.7 git tools - subtree merging example.
the 'sub' project included subdirectory in 'main' project.
after make change 'sub' project, git reports conflict when try merge change 'main' project.
test summary
- created repos projects 'main' , 'sub' (sub instead of rack)
- add remote named sub_remote main refers sub
- track sub_remote using sub_branch
- change , commit 1 line in file in 'sub' project
- pull changes sub on main/sub_branch
- merge main/sub_branch main/master.
the merge fails conflict. merge confused version of changed line keep.
<<<<<<< head main ======= main upstream change >>>>>>> sub_branch main.git sub sub.git tm
complete test script
#!/bin/sh # initialize empty repos in main sub 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 sub ls > sub/data cd sub git add data git commit -m "added data" git push origin master cd .. # add sub 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 sub cd sub sed -i -e 's/main$/main upstream change/' data git commit -a -m "upstream change made data" git push origin master cd .. # merge sub change main cd main git checkout sub_branch git pull #merge sub_branch changes master git checkout master git merge -s subtree sub_branch cat sub/data
what read-tree
doing in case adding directory in current tree contents of tree. contents added regular file , directories being created , added, there no history carried over. these files treated if created them.
when try merge process fails since sees sub_branch history created data
file, , target directory contain different data
file created you.
the page using missing important step make subtree works properly, can able pull updates it.
the proper example can seen in both these pages: https://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html https://help.github.com/articles/working-with-subtree-merge
what missing in case link history when create subtree:
# create merge record not change in tree yet git merge -s ours --no-commit sub_branch # bring changes , place them in proper subdirectory git read-tree --prefix=sub/ -u sub_branch
after main
repository contain history of sub
repository. calls merge failing should work properly. calling git log --graph
let see how different commits being merged.
Comments
Post a Comment