Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all renames in all commits on git?

Tags:

git

I'm lost in a repo maze with a bunch of files that were readded while their older version was renamed because of a not-so-good rebase that was made.

Anyway, I want to list all the files that at some point were renamed, that is, list all renamed files from all commits.

like image 939
Roberto Avatar asked Oct 02 '22 02:10

Roberto


1 Answers

Would this suffice?

git whatchanged -M5 --summary | grep rename | grep '=>'

Here is a modified version which will do renamed and deleted files:

git whatchanged -M5 --summary | grep -E 'rename.*=>|delete mode'

This will give you all renames from the HEAD of your current branch and it's ancestry including merged parents up to the very first commit. The -M5 will have files that are similar by 50% or more reported as a rename; this may be to low of a percentage but you can change it (The 5 is read as .5, or 50% so you could change it to M8 for 80%). Be warned, it will take a long time if there are a lot of commits.

I suggest you limit the range of commits such as:

git whatchanged -M5 --summary <commit-id>..HEAD | grep rename | grep '=>'

As far as I can tell you will need to start with a commit, I am not sure how you could get a comprehensive list of renamed files across all branches and tags at once. If you have divergent branches you want to check, or branches with independent commit histories in a single repo, you will need to run the suggested command on each branch.

like image 154
James Avatar answered Oct 13 '22 11:10

James