Skip to main content
added 2 characters in body
Source Link
Mark Longair
  • 472.1k
  • 77
  • 427
  • 330

I've only given this cursory testing myself, but I think you can use git filter-branch with --tree-filter to rewrite the branch, but removing all files apart from those in the subdirectory ABC/DEF, with something like the following:

git filter-branch --tree-filter \ 'find . -path ./ABC/DEF -prune -o -type f -print0 | xargs -0 rm -f' \ --prune-empty HEAD 

Note that the findfind command only removes files, not directories, but since git doesn't store empty directories, this should still produce the result you want.

I've only given this cursory testing myself, but I think you can use git filter-branch with --tree-filter to rewrite the branch, but removing all files apart from those in the subdirectory ABC/DEF, with something like the following:

git filter-branch --tree-filter \ 'find . -path ./ABC/DEF -prune -o -type f -print0 | xargs -0 rm -f' \ --prune-empty HEAD 

Note that the find command only removes files, not directories, but since git doesn't store empty directories, this should still produce the result you want.

I've only given this cursory testing myself, but I think you can use git filter-branch with --tree-filter to rewrite the branch, but removing all files apart from those in the subdirectory ABC/DEF, with something like the following:

git filter-branch --tree-filter \ 'find . -path ./ABC/DEF -prune -o -type f -print0 | xargs -0 rm -f' \ --prune-empty HEAD 

Note that the find command only removes files, not directories, but since git doesn't store empty directories, this should still produce the result you want.

Source Link
Mark Longair
  • 472.1k
  • 77
  • 427
  • 330

I've only given this cursory testing myself, but I think you can use git filter-branch with --tree-filter to rewrite the branch, but removing all files apart from those in the subdirectory ABC/DEF, with something like the following:

git filter-branch --tree-filter \ 'find . -path ./ABC/DEF -prune -o -type f -print0 | xargs -0 rm -f' \ --prune-empty HEAD 

Note that the find command only removes files, not directories, but since git doesn't store empty directories, this should still produce the result you want.