git-subtree pull complications
Solution 1
I had the same problem, and in my case it seems to be due to the initial subtree commit being merge-squashed into the master branch.
Looking through the subtree source I found this: https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh#L224
It looks like subtree greps your git log for git-subtree-dir: foo
but doesn't find a suitable commit. Try git log --grep="git-subtree-dir: foo/*\$"
, and if there's something weird with that commit, such as it being a merge commit, that could be the issue.
Just pulling without squashing worked for me, apart from the annoying merge conflicts. I did that in a temporary branch which I then git merge --squash
ed into another branch to avoid a messier history. It could've been rebased instead too of course.
Solution 2
I've been experiencing the same error Can't squash-merge: 'foo' was never added.
with sourcetree 1.7.0 whenever I do a pull on a subtree.
However, I believe my case is different because I'm using subdirectories.
Sourcetree does something as follows:
git -c diff.mnemonicprefix=false -c core.quotepath=false subtree pull -P dir1\subdir1 --squash remote-repo master
And obviously, if we were to try it again in Git Bash (Git version 2.6.1.windows.1), it would be:
git subtree pull -P "dir1\subdir1" --squash remote-repo master
However that failed. The following also failed although the command syntax is fine:
git subtree pull -P dir1/subdir1 --squash remote-repo master
The solution I found to make it work is to use Git Bash with the following command:
git subtree pull -P "dir1/subdir" --squash remote-repo master
I guess that there is still some work to be done for Git's command-line processing engine.
Solution 3
This also happens, if the current clone is a partial clone (e.g., when using --depth=1
). This is the default at GitHub Actions V2.
In the case of GitHub actions, this can be configured when using fetch-depth: 0
at the checkout step:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v2
with:
ref: master
fetch-depth: 0
Solution 4
This could happen when the main repository and the subtree repository has different set of commits.
In my case I had updated the subtree from the local repository(using git subtree pull --squash -P foo local/foo.git master
) and the local repository changes were never pushed to origin.
When I tried git pull --squash -s subtree [email protected]:foo.git master
after this, I started getting the error.
Just pushing the subtree repository solved the error.
Related videos on Youtube
David H. Clements
Updated on June 12, 2022Comments
-
David H. Clements almost 2 years
We have been trying to get git-subtree working on a project (with git version 1.7.9.4) and have run into a bit of a complication. Someone else previous added the subtree with this command some months ago:
git subtree add --prefix=foo [email protected]:foo.git master
Now there have been substantive changes to
foo
and we'd like to merge in those changes, ideally squashing them in. None of the files have been modified since they were imported.I've tried three things to try and merge in the changes.
First:
git subtree pull --squash -P foo [email protected]:foo.git master
Which throws the exception:
Can't squash-merge: 'foo' was never added.
Second:
git subtree pull -P foo [email protected]:foo.git master
This works (sort of), but has the issue of pulling in all of the commits and has conflicts with the files that have been modified.
Finally, I tried this:
git pull --squash -s subtree [email protected]:foo.git master
This gives me the desired result, with the output
Automatic merge went well; stopped before committing as requested
and all of the files showing up as modified (with the correct content).Ideally I'd like to continue using first
git-subtree
version and get an output close to the last version. If we have to use the last version consistently going forward, we will, but I am a little confused as to why the last one doesn't produce merge conflicts while the middle one does.Any help is appreciated.
-
David Svensson over 8 yearsI had the same problem which turned out to have been caused by me missing a sub-folder in the prefix option when trying to pull. Adding this as a comment since the error message does not give any indication of this error and the troubleshooting led me here.
-
Arkadiy Kukarkin over 7 yearsThanks, this is useful. I had a related issue where I moved the subdir after adding the subtree into it, which seems to trip up this match
-
Alex Brown over 4 yearsI had this problem, and it was due to our stashweb policy which squashes commits. I was able to fix it by finding a subtree commit and using
git merge -s ours <commit>
to bring it into history.