We have been using git subtrees for a while, and there's a recurring issue I've only now pinpointed. We split some library code out to a separate git repo, and different people tend to work on both the subtree repo (I'll call remote from now on) and the original parent repo (I'll call parent). We don't normally squash, neither when pulling or pushing.
The issue is that, when pushing from parent to remote, the commits pushed have their hash changed. I can't tell whether this happens on every push or not (and it's hard to play around with since pushing takes 4+ hours), but every commit pushed had its hash changed last time I did a git subtree push
.
This causes issues down the line, where when we do a pull next time, odd merge conflicts happen, and these commits get pulled in again as if they were new, since their hashes differ.
The only thing I have to go on is an error that gets reported while pushing:
fatal: ambiguous argument '544c7a6e7cb3e15be01870bbfe3f30163de5cca6^0': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
could not rev-parse split hash 544c7a6e7cb3e15be01870bbfe3f30163de5cca6 from commit 702e4af8abb4a1c6b35301d5632c290f48095d8c
This does not stop the push from happening, it goes on as usual.
Now, when looking at commit 702e4af8abb4a1c6b35301d5632c290f48095d8c
, it's a squash merge from remote to parent.
The commit message says:
Squashed <prefix name> changes from 925a2ddd9e..544c7a6e7c
Commit 544c7a6e7c
isn't in the parent's working tree, but it is in the remote, and it's a merge commit.
For now, I've resorted to doing a git pull, git push and then a git pull again to pull in the duplicate commits again. Obviously this results in duplicate commits and isn't ideal, but I'm at least hoping to get rid of the odd merge conflicts next time I pull from the remote.
This looks like a bug in git, since i would never expect a push to change commit hashes, but if the split hash error is causing it, I'm not sure how to fix it.