Moving multiple directories from one git project to another, keeping their history

I would like to move multiple directories from one git project to another, preserving their history. The problem is that all the examples that I see show how to make directory extraction into my own git project, keeping history with git filter-branch . Is it possible to move these directories from one repository to another, preserving my history if the recipient repository already has other files with the version (not contradicting those that need to be moved)?

Can someone please show me an example of how to do this? Thanks!

+4
source share
1 answer

Answering my question with this small script, I knocked on bash (be sure to read it first and copy your files):

 #!/bin/bash gitURL=$1 project=$2 srcProjectBaseDir=$3 destProjectBaseDir=$4 # Remove stale checkouts in order to do a clean clone rm -rf ${srcProjectBaseDir} git clone --no-hardlinks $gitURL ${srcProjectBaseDir} cd ${srcProjectBaseDir} git remote rm origin # These make sure your extracted module is called as the directory name. # If this is of no interest to you, comment out these three lines and you # should be alright. mkdir temp git add temp git mv ${project}/ temp/ git commit -m "Refactoring: Isolated files for filter-branch." git filter-branch --subdirectory-filter temp HEAD git add . git commit -m "Refactoring: Filter branched." if [ ! -d ${destProjectBaseDir} ]; then mkdir ${destProjectBaseDir} cd ${destProjectBaseDir} git init cd .. fi cd ${destProjectBaseDir} git remote add repositoryAbranch ${srcProjectBaseDir} git pull repositoryAbranch master git remote rm repositoryAbranch 

This script is based on most of the instructions that are visible here (with a few additions).

+2
source

Source: https://habr.com/ru/post/1494344/


All Articles