I actually have two repositories:
main
external
The main
repository was merged after some time into external/main
directory (as subtree).
Now I'd like to migrate the changes made to external/main
back to main
repository, but only these commits and no other unrelated commits like to external/<anything-else>
.
I've actually tried the classical:
git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter main -- --all
but that removes all the commits made to the initial main
repository too and only leaves the ones which were made in the external
git repository.
So: how to retain only the commits:
a) made to the initial main
repository
and
b) made to the subtree of external
(external/main
)
When I try git pull -s subtree ../external
, the commits are all merged, including commits which didn't change anything in the subtree. I'd like to have only the commits which actually changed something in the subtree and there also only the information about files from the subtree.
git-filter-branch can be used to get rid of a subset of files, usually with some combination of --index-filter and --subdirectory-filter .
The git fetch command downloads objects to the local machine without overwriting existing local code in the current branch. The command pulls a record of remote repository changes, allowing insight into progress history before adjustments.
Use git subtree split to extract the files you want to the an intermediate branch in your repository (you have already done this).
You should be able to limit the commits rewritten by filter-branch
using --not --remotes
in the <rev-list options>
section of your command:
git filter-branch --tag-name-filter cat --prune-empty
--subdirectory-filter main -- --all --not --remotes
This will cause filter-branch
not to include commits reachable from your remote branches. If you have multiple remotes, you can use something like --remotes=origin
to specify which one to consider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With