Saturday, March 20, 2021

Git extract folder from project with history and tags

 When you want to split gut repositories and save history `Here is a brief note on the use of gut filter branch split.

I had some problems finding the right parameters. If it can help others, you can get the command here.

If you are not yet familiar with the possibilities of the Gut Filter Branch of, I suggest you consider Gut Book: Writing History, which is a good introduction to the command.

Now, to get started, you should clone the repository you want to convert (since you will write the entire date in the new RIPs).

In short, without further explanation:

ORIG=path_to_original_repos
DEST=destination_of_rewritten_repos
DIR=directory_you_want_to_extract_from_ORIG

git clone $ORIG $DEST && \
cd $DEST && \
git filter-branch --prune-empty --tag-name-filter cat --subdirectory-filter $DIR -- --all

A few notes:

  • --prune-empty will remove all commits that has no relation to the folder you extract
  • --tag-name-filter cat will also rewrite any tags you put on the commits that are rewritten
  • --subdirectory-filter takes a foldername as parameter, but I needed to add -- --all to make it work

 

One Response to “Git extract folder from project with history and tags”

I’ve been having problems with Git every I started applying it, especially because a mistake is quickly made. That said, I love how easy it is to undo mistakes. So thanks for the “- –all comment”, I’ve just tested it and to be honest, didn’t even know I could split AND preserve the history.

 

No comments:

Post a Comment

Nokia X10 and X20 announced: 5G support and 3 years of software updates and warranty

 The Nokia X has been associated with a variety of phones in the past. Multimedia, Microsoft-backed Android phones, then HMD-made Android fo...