or – Paolo Redaelli https://monodes.com/predaelli A civil engineer with a longlife fondness for Software Libero Sat, 31 Aug 2024 22:23:46 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 91795679 Git: Copy a file or directory from another repository preserving the history https://monodes.com/predaelli/2024/09/01/git-copy-a-file-or-directory-from-another-repository-preserving-the-history/ https://monodes.com/predaelli/2024/09/01/git-copy-a-file-or-directory-from-another-repository-preserving-the-history/#respond Sat, 31 Aug 2024 22:23:45 +0000 https://monodes.com/predaelli/?p=11886

How to copy a file or directory from another GIT repository while preserving its history?

Internet is full of magic formulas each one more complex.

Here I’m proposing a much simpler and faster one that is to make a git format-patch for the entire history of the file or subdirectory that we want and then import it into the destination repository.

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

Simple and fast :)

Source synaptic fault http://blog.neutrino.es/2012/git-copy-a-file-or-directory-from-another-repository-preserving-history/ ]]>
https://monodes.com/predaelli/2024/09/01/git-copy-a-file-or-directory-from-another-repository-preserving-the-history/feed/ 0 11886