Search code examples
gitgit-filter-repo

git filter-repo: can it be used on a specific branch?


I'm reading about what git filter-repo can do because I want to do a small experiment with it.... I have this repo where I only want to get the history of one directory from, say.... master..... but I don't want to work on master. I would like to create a new branch, say filter-repo-test and let git filter-repo run its magic on this branch alone. I'm reading the manual but I don't see an option to specify only a given branch. Is it possible?

https://htmlpreview.github.io/?https://github.com/newren/git-filter-repo/blob/docs/html/git-filter-repo.html


Solution

  • The 'Miscellaneous Options' includes --refs

    --refs <refs+>

    Limit history rewriting to the specified refs. Implies --partial.
    In addition to the normal caveats of --partial (mixing old and new history, no automatic remapping of refs/remotes/origin/* to refs/heads/*, etc.), this also may cause problems for pruning of degenerate empty merge commits when negative revisions are specified.

    And... it will move tags, as I documented in "Git Subdirectory Filter with tags", which does uses --refs, as an example.


    As Ryan Wheale notes in the comments:

    You should be able to use the branch name to limit the filtering to the branch.
    Again, take note of the caveats of --partial.

    --refs filter-repo-test