Partial subtree upstream push in Git

698 views Asked by At

I have a situation in Git in which I have a core repo that is shared/used with other repos via Git subtree. In repo "project", I have the subtree repo "core" and in that core I made various commits that I have since committed and pushed to "project". I now want to push these changes in the "core" folder to the actual "core" repo. This would normally be accomplished with:

git subtree push --prefix=/core/ core-repo master

However, there happens to be a single commit in the "core" folder that I would like to keep local to "project". The cheap hacky way would be to just push everything upstream and then revert that one commit. I was wondering if there was a more appropriate way though to stop those particular changes from ever going upstream. Thanks.

1

There are 1 answers

2
mziccard On

Usually you can push up to a specific commit with:

git push <remotename> <commit SHA>:<remotebranchname>

This will push to the remote branch all commits up to the one specified (included).

You should be able (but I have not tested it) to do this also with a subtree push. Something like:

git subtree push --prefix=/core/ core-repo <commit SHA>:master

In your case <commit SHA> should be the commit preceding the one you want to avoid to push.
Notice that, if you have commits that follow the one you do not want to push, you will have to reorder commits using git rebase.