Skip to content

Instantly share code, notes, and snippets.

@imagejan
Created March 22, 2019 13:46
Show Gist options
  • Save imagejan/1479b866ff97e37419aa212a10516f01 to your computer and use it in GitHub Desktop.
Save imagejan/1479b866ff97e37419aa212a10516f01 to your computer and use it in GitHub Desktop.
Copy files or directories from another git repository preserving the history
# see http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/
mkdir /tmp/mergepatchs
cd ~/repo/org
export reposrc="path/to/file1 path/to/file2"
git format-patch -o /tmp/mergepatchs $(git log $reposrc|grep ^commit|tail -1|awk '{print $2}')^..HEAD $reposrc
cd ~/repo/dest
git am /tmp/mergepatchs/*.patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment