Skip to content

Instantly share code, notes, and snippets.

@kousu
Created March 19, 2021 20:17
Show Gist options
  • Save kousu/c1dcb8f7ef3c208f003bc40252e01be7 to your computer and use it in GitHub Desktop.
Save kousu/c1dcb8f7ef3c208f003bc40252e01be7 to your computer and use it in GitHub Desktop.
Repo splitting with git filter-repo

To split the GUI plugin, spread over two branches (1 2) and two folders (shimmingtoolbox/gui/, shimmingtoolbox/fsleyes-plugin-shimming-toolbox), out from [email protected]:shimming-toolbox/shimming-toolbox.git to [email protected]:shimming-toolbox/fsleyes-plugin-shimming-toolbox.git:

  1. sudo pacman -S git-filter-repo [or your local option]
git clone [email protected]:shimming-toolbox/shimming-toolbox.git shimming-toolbox
git clone [email protected]:shimming-toolbox/shimming-toolbox.git shimming-toolbox-plugin
(cd shimming-toolbox; git filter-repo --invert-paths --force --path shimmingtoolbox/gui/ --path shimmingtoolbox/fsleyes-plugin-shimming-toolbox)
(cd shimming-toolbox-plugin; git filter-repo --force --path shimmingtoolbox/gui/ --path shimmingtoolbox/fsleyes-plugin-shimming-toolbox)
  1. Upload the original copy
(cd shimming-toolbox;
git remote add origin [email protected]:shimming-toolbox/shimming-toolbox.git # filter-repo seems to have erased all remotes? probably as a safety precaution
git push --all --force) # danger!
  1. Make a new empty repo on github for the split copy

  2. Upload the split copy

This is a bit trickier because this repo has a blank master that we need to merge with before things will work. The original repo got to keep its master (thanks to --invert-paths):

(cd shimming-toolbox-plugin;
git remote add origin [email protected]:kousu/fsleyes-plugin-shimming-toolbox.git
touch README.md; git add README.md; git commit -m "initial commit" # in your case, you could do a `pull` to get the README you have on github already
git config merge.ff true # override my personal git config --global merge.ff only setting
git checkout ad/fsleyes
git merge master --allow-unrelated-histories
git checkout ah/plugin-package
git merge master --allow-unrelated-histories
git push -f --all origin
)
  1. Go on github and remake the pull requests for the two branches in the new repo.
@kousu
Copy link
Author

kousu commented Mar 20, 2021

Oh no! This has a critical flaw! If used with Github (and where else would you?) it ends up rewriting your entire history, giving new commit IDs to everything, not just commits that touched the filtered files, because it drops commit signatures and Github puts signatures on everything edited via the web editor. So if you ever edited your README quickly online, every commit after that point will end up with a different sha1, by in-fucking-duction, and you'll break your entire repo. At least git-filter-branch only touches one branch at a time.

god fucking dammit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment