0

I'm try ing to set up git subtrees ti mage shared utils and TS types in a couple repos. I'm confused on how git handles squash-merges in subtrees and right now I'm runnning into errors.

Let's say I have a repo project and have set up another repo utils I'm using as a subtree. My main project looks like this:

project/
├── fileOne.ts
├── utils/
│   ├── fileTwo.ts

Then I make some changes so my project's commit history appears as follows

ddddddd (HEAD -> main, origin/main) edit fileTwo
ccccccc edit fileOne
bbbbbbb add fileTwo
aaaaaaa add fileOne

I push these up directly to main in project. I also push to a new branch in my utils repo using

git subtree push -P utils utils-remote my-new-branch

The commit history for my-new-branch is

ggggggg (utils-remote/my-new-branch) edit fileTwo
fffffff add fileTwo
eeeeeee (utils-remote/main) some older commit

Then, I squash merge my-new-branch into utils/main so the commit history looks like

hhhhhhh (utils-remote/main) add and edit fileTwo
eeeeeee some older commit

Now the subtree in project and the utils remote have diverged in that the remote contains a squashed commit, but the subtree in project has the 2 original commit. Does git do anything handle this discrepancy? If not how can I as a developer get the subtree in project back into sync with the subtree remote so I can pull new changes?

Using git pull in this case (with or without the squash option) seem to be giving errors. Can't squash-merge: 'utils' was never added. and fatal: refusing to merge unrelated histories respectively.

  • Combining `git subtree` with squash merge seems like a bad idea in general. Note, however, that `git subtree` is rather sadly neglected now and has known bugs that nobody has bothered to fix. Someone with time and energy and enthusiasm for `git subtree` (i.e., someone not me) needs to adopt it and clean it up. – torek Dec 20 '22 at 01:08

0 Answers0