Search code examples
gitgit-log

How to get all the renames in a folder's history?


I will use git filter-repo to extract a folder and its history from a repository.

Its documentation says,

Note that much like git itself, renames are NOT followed so you may need to specify multiple paths, e.g. --path olddir/ --path newdir/

That's saying that I should to specify explicitly the previous names of files outside the folder, so that their history is retained too.

Is there a convenient way to get the old names of all files in a folder?

The help for git log --follow says, "(works only for a single file)" -- so an algorithm might be:

  • For each file in folder
    • Run git log --follow
    • Parse the git log output to look for any renaming in the history

I suppose I can do that -- i.e. write a script to issue git log --follow commands for each file, and parse the output -- is this the best or only way?


Solution

  • Running git filter-repo --analyze produces various files including renames.txt.

    It's not filtered per-path, it's for the whole repository.

    You can parse it to find/filter whatever folders interest you.