Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jakub-g/git-move-folder-between-repos-keep-history

:heavy_dollar_sign: :heavy_plus_sign: :heavy_minus_sign: :white_check_mark: Move folder from one git repo to another, with full history.
https://github.com/jakub-g/git-move-folder-between-repos-keep-history

Last synced: about 1 month ago
JSON representation

:heavy_dollar_sign: :heavy_plus_sign: :heavy_minus_sign: :white_check_mark: Move folder from one git repo to another, with full history.

Awesome Lists containing this project

README

        

# git-move-folder

Move folder from one git repo to another, with full history.

*Note: git sha1-s are not preserved after migration (it's not possible in general case; before merging code from one repo to another, the script recreates git commits, filtering out the changes done outside of the folder being moved)

# Usage

Check the `.sh` file. You don't need advanced bash skills. Basically you should:

1. Copy this file to a handy place (outside of the repos you modify)
2. Modify the variables the top of the file
3. Make sure the repos modified are in clean state (`git status`)
4. Run the `.sh` file and let it do the magic

Note that the script will go over each commit in git history one by one, so it may take a while to complete on huge repos (progress is logged though on each commit).

It is however optimized to skip the commits that do not touch the folder moved, so if the folder is just a small part of a huge repo, it should be relatively fast.

If something goes wrong, you can comment out (with `#`, or just delete the line) the `importFolder...` method call at the end of the file, uncomment the `undoImport...` method call, run the script to undo, then modify the params or the code itself, and rerun.

Even if I put a lot of safety belts (`verifyPreconditions`) and an undo functionality , for extra safety, DO NOT RUN THIS SCRIPT ON YOUR ORIGINAL REPOS. Make full copies of the repos you want to play with before running the script - better safe than sorry. The script uses some dangerous git methods that rewrite repo history.

You've been warned :) Now back up your stuff and enjoy the script.

If you liked it, [please upvote my StackOverflow answer](https://stackoverflow.com/a/47081782/245966).