Skip to content

Instantly share code, notes, and snippets.

@travi
Last active September 9, 2022 14:36
Show Gist options
  • Save travi/5ffc2c73511dc49fb811741ed365756a to your computer and use it in GitHub Desktop.
Save travi/5ffc2c73511dc49fb811741ed365756a to your computer and use it in GitHub Desktop.
extract from git with history

some steps from http://www.pixelite.co.nz/article/extracting-file-folder-from-git-repository-with-full-git-history/

From the original repository:

git log --pretty=email --patch-with-stat --reverse --full-index --binary -- <path/to/file_or_folder> [path/to/additional/file/or/folder] > /tmp/<patch name>`

In the repository where the history should be imported:

  1. from master, git checkout -b <name of pre-release branch>
  2. git checkout --orphan <name of orphan branch>
  3. git reset to unstage the files that already existed in the repository
  4. rm -rf * to remove the previous files that are now unstaged (be careful to not remove the .git/ directory)
  5. git am < /tmp/<patch name> to apply the patch to the orphan branch
  6. git merge <name of pre-release branch> --allow-unrelated-histories
  7. verify that existing and extracted/imported tests pass
  8. repeat with additional patches if missing dependencies are discovered
@travi
Copy link
Author

travi commented Sep 9, 2022

https://github.com/newren/git-filter-repo/#solving-this-with-filter-repo is another option that i've used successfully. this is especially useful when keeping tags is desired.

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