简体   繁体   中英

git subtree split - the tags are not transferred

I have a git project that has one big root directory:

C:\MyProject\MyProject
C:\MyProject\.git

And then all the files and subdirectories are inside C:\\MyProject\\MyProject . I want to remove that redundant root directory, so I used this command:

git subtree split -P MyProject -b MyBranch
git checkout MyBranch
git branch -D master
git branch -m MyBranch master

There is a problem with this solution, however - the tags are still attached to the now-deleted , original master branch:

在此输入图像描述

The gray branch is the original master branch, the red branch is the new one without the redundant directory, but the tags are still attached to the old branch's checkins.

git filter-branch might be able to do the movement you want and migrate all branches and other references, like tags. The --subdirectory-filter will do an operation similar to the subtree that you are creating:

git filter-branch --prune-empty --subdirectory-filter subDirectory -- --all

Check this other answer for better detail on how to setup the repository for this kind of operation.

I tried

git filter-branch --prune-empty --subdirectory-filter <ProjectSubFolder> 
--tag-name-filter cat -- --branches

That transfered the tags too but kept a dangling branch with tracking references so I removed by hand the file .git\\refs\\original\\refs\\heads\\master and the dangling branch dissappeared.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM