subtree merge claims already up-to-date

302 views Asked by At

I haven't had much luck pushing/pulling changes from subtrees. Usually I use the 'git subtree' command to create the subtree and pull changes. When pulling I get lame conflicts to fix (when there really is not conflict) and pushing never works.

So today I am trying a different approach, using subtree merges instead of the git subtree command. I followed the instructions at https://help.github.com/articles/about-git-subtree-merges/.

First, I create the remote to the repository I want to use as a subtree:

git remote add -f cumulonimbus-machine http://github.com/fschwiet/cumulonimbus-machine
git merge -s ours --no-commit cumulonimbus-machine/old
git merge -s ours --no-commit cumulonimbus-machine/fschwiet

The 'old' branch is a parent of the 'fschwiet' branch. I wanted to base the subree on 'old' initially so I can test pulling changes (pulling the remainder of 'fschwiet'). Anyhow, I create the subtree:

git read-tree --prefix=host/ -u cumulonimbus-machine/old

This works fine. All the files are in the hosts folder, and I can see its the older branch as expected. Then I try to get some updates:

git pull -s subtree cumulonimbus-machine fschwiet

and I get some disappointing output:

From http://github.com/fschwiet/cumulonimbus-machine
 * branch            fschwiet   -> FETCH_HEAD
Already up-to-date

I expected this last pull would update the host directory to have the latest from the 'fschwiet' branch. But it hasn't pulled down anything. I did verify 'old' and 'fschwiet' are not actually the same commit. I tried pulling some other ways with the same results:

git subtree merge --prefix=host cumulonimbus-machine/fschwiet
git merge -X subtree=host cumulonimbus-machine/fschwiet
git subtree pull --prefix=host cumulonimbus-machine 90686ba2d0c31afdc516611064
git subtree pull --prefix=host cumulonimbus-machine master

What did I miss?

1

There are 1 answers

0
Frank Schwieterman On

My mistake was in running

git merge -s ours --no-commit cumulonimbus-machine/fschwiet

before

git read-tree --prefix=host/ -u cumulonimbus-machine/old

This created a merge commit pulling in the contents of the 'old' branch, but telling the repository it was in sync with the 'fschwiet' branch.

I did learn something valuable after all this though. It seems some of the merge problems I've had may be resolved if I used

git merge -X subtree=host cumulonimbus-machine/fschwiet

instead of git merge -s subtree or git subtree merge. This seems to do a smarter merge algorithm. In particular, it removed files that were deleted (unlike git subtree merge).