简体   繁体   中英

Convert subdirs in Git branch to new branches

I have a branch in my git repo called "releases" and it contains subdirectories "1.0" and "1.1". I'd like to have these two subdirs become branches at the "releases" level and remove the releases directory entirely. This was a side effect of converting an old svn repo to a git repo (combined with a little inexperience on my part). Is there a simple way to do this? Like maybe move the 1.0 and 1.1 dirs up a level in the local repo, and then do something like:

git checkout -b 1.1 
git push origin 1.1

I don't think that is the best solution because it doesn't preserve the history since every file has to get re-checked in. Is there a better approach that doesn't involve a history altering push?

Since you want to remove the releases directory there is no way you don't add to history. So the simplest way would be to checkout the releases branch, checkout a rel-1.1 branch, reset this to the commit the rel-1.1 happened, move the dir (check What's the purpose of git-mv? ) rince and repeat for rel-2.2 then delete the releases branch.

If however you can rewrite the whole repo history, check git filter branch command - see here for instance for how to rewrite all history to move a directory on top level, exactly what you want: How can I move a directory in a Git repo for all commits? . So you can use filter branch to rewrite the history of the releases branch as the two dirs were always on top level (you have to checkout rel-1.1, 1.2 branches before you start of course) - then create the two branches you want.

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