Filtering history for files at the root of a directory
Given that you have the following directory structure in your repository:
dir1/
file1
file2
dir2/
file3
file4
dir3/
file5
If you want to create a new repository containing just file1 and file2 (and the history) you can run the following commands:
git filter-branch --prune-empty --subdirectory-filter dir1 master
git update-ref -d refs/original/refs/heads/master
git filter-branch --prune-empty --index-filter 'git rm -r --cached --ignore-unmatch dir2' --tag-name-filter cat -- --all
This will give you a new history of all commits that contain file1 and file2
Written by David North
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Git
Authors
khasinski
591.1K
dmichaelavila
500.4K
Related Tags
#git
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#