I trying to move some files with their history from one repository to another. There are many topics which discuss this, but i hit some problems which I did not see mentioned yet.
So the steps i do are:
git clone --no-local --no-hardlinks /path/to/origninal-rep repA
cd repA
git remote rm origin
git filter-branch -f --prune-empty --index-filter "git rm --cached --ignore-unmatch $(git ls-files | grep -v 'include/file1.h\|include/file2.h')"
with an intention to keep history related only to those two files and move them to another repository. However, i hit the following problem:
Rewrite 6768c299b2b25754a558336e025ce92576c954f2 (1/200)/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git-filter-branch: line 329: CMakeLists.txt: command not found ....
Strangely enough i can remove files one-by-one, this works for example:
git filter-branch -f --prune-empty --index-filter 'git rm --cached --ignore-unmatch .gitignore' HEAD
I also tried this on the dummy repository (with only couple of files) and everything worked fine! So it does not work in real life, perhaps somewhat related to the length of the output of git ls-files
?..
UPDATE:
I keep looking for solution, i wonder what should be the output of git ls-files
? I have files listed with line breaks (1 file per line), whereas it seems that git rm
should have files in one line, e.g. :
git filter-branch --prune-empty --index-filter 'git rm --cached --ignore-unmatch DIR_1/* DIR_2/*' HEAD
could that be a problem?
UPDATE2:
I followed this solution to achieve the goal, everything worked.