Search code examples
gitshellgit-subtree

git subtree useless merge


I added a subtree into my project demo this way

$ git subtree add --prefix=plugins/plugone plugone master --squash
$ tree .

demo
|___.git
|___plugins
       |___plugone

$ git log --oneline --all --graph --decorate

* 200e94c (HEAD -> master, origin/master) Merge commit 'f9a745bb60b3e5816f918c0ec736714bd362bce7' as 'plugins/plugone'
| \
|  * f9a745b Squashed 'plugins/plugone/' content from commit 5c4a153
* 947ebfe bla bla

So far so good, I'm happy with subtree. Then I edited a file into the subtree plugone and committed and subtree pushed

* 07b3046 (HEAD -> master, origin/master) plugone append #1
* 200e94c Merge commit 'f9a745bb60b3e5816f918c0ec736714bd362bce7' as 'plugins/plugone'
| \
|  * f9a745b Squashed 'plugins/plugone/' content from commit 5c4a153
* 947ebfe bla bla

I noticed that after I updated plugone from my project demo through git subtree push --prefix=plugins/plugone plugone master, when I run

$ git subtree pull --prefix=plugins/plugone plugone master --squash

I expected this to do nothing, but I noticed new commits in the demo project:

*   a5ab686 (HEAD -> master) Merge commit 'c8cd6206950dc45196cf6fd1f17e8587a115fee6'
|\
| * c8cd620 Squashed 'plugins/plugone/' changes from 5c4a153..1fd84fe
* | 07b3046 (origin/master) plugone append #1
* |   200e94c Merge commit 'f9a745bb60b3e5816f918c0ec736714bd362bce7' as 'plugins/plugone'
|\ \
| |/
| * f9a745b Squashed 'plugins/plugone/' content from commit 5c4a153
* 947ebfe blabla

This is very embarrassing because it means that my colleagues and I have to run git subtree pull after every git subtree push which IMO doesn't make much sense.

How to prevent this behavior ?


Solution

  • Well another way does exist to do that but in a bit harder way (more command to run). Instead of using , I tried git read-tree/merge and it gives something IMO nicer...

    The advantage is that I don't need to install extra tools...

    Here is a helpful article that describes well how to use subtree concept manually https://delicious-insights.com/en/posts/mastering-git-subtrees/#subtrees-step-by-step