Git Subdirectory Filter with tags

百般思念 提交于 2019-12-21 21:36:39

问题


I am attempting to split a large repo into multiple smaller ones. The goal is to split a folder and retain the tags in the process.

I have tried:

git filter-branch --prune-empty --subdirectory-filter my-folder develop

This correctly place my-folder at the root of the new project, and retained the tags. However checking out a tag resulted in seeing the entire old directory structure within the new repo.

So I tried:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter my-folder -- --branches=develop --tags

This results in the develop branch being there with the old directory structure, BUT when I checkout a tag I see the subdirectory correctly filtered to the root! So the tags are correct but not the develop branch. Basically it has the opposite problem to the first method.

I am at a loss as to why the second method did not work. I would really appreciate any pointers!

EDIT:

Trying this now:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter my-folder -- --all

Was hesitant as I expect that this will take quite a bit longer. This did take longer, but it mostly worked. What did not work? Well the older tags in which the folder had not yet been created were left in the repo and when checked out contained the full (very) old directory structure. I had to grep and delete all these tags. Still the repo is not as small as I wuold have expected...


回答1:


As I mentioned in "Git commands that could break/rewrite the history", the old git filter-branch command is slowly being deprecated.

Using the new git filter-repo, that would be:

 git filter-repo --path my-folder/ --to-subdirectory-filter / -- refs develop

Then push that one branch to a new empty Git repository.

That should move the relevant tags correctly.



来源:https://stackoverflow.com/questions/58394471/git-subdirectory-filter-with-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!