Skip to content

Instantly share code, notes, and snippets.

@urecho
Created March 3, 2015 00:56
Show Gist options
  • Save urecho/55c2e1e201c9964f6c36 to your computer and use it in GitHub Desktop.
Save urecho/55c2e1e201c9964f6c36 to your computer and use it in GitHub Desktop.
Git: Copy a file or directory from another repository preserving the history
src : http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/
mkdir /tmp/mergepatchs
cd ~/repo/org
export reposrc=myfile.c #or mydir
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