2p6r5w
Last Updated: February 25, 2016
·
474
· hobnob
Dave

Filtering history for files at the root of a directory

git

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

Say Thanks
Respond