Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my git file history lost after performing a move refactor in eclipse?

Tags:

git

eclipse

egit

I've performed several refactors in eclipse where I move a large set of files to another java package. These often result in a lot of files being automatically updated to resolve references. So, the commits in these cases tend to be quite large.

I assumed that git tracked the renames and I could use git log --follow to follow the history back through the rename, but git didn't track the renames.

I've performed smaller refactor operations in eclipse where the renames are detected on commit. The only difference seems to be the size of the commits.

Any ideas?

like image 360
Jonathan Avatar asked Oct 04 '12 20:10

Jonathan


1 Answers

Git does not track renames in history at all, but git log can heuristically detect renames based on the commit contents.

  • You may need to specify a low -M percent to git log in order for the renames to be detected. If more than some percent of the file has changed, git log (and git diff) won't consider an add/delete pair to be a rename. If the files moved were very small and required content changes (to package names for example) then they might exceed this threshold.
  • You may need to specify a value for -l too, which specifies the maximum number of potential renames to evaluate. In large commits, you may very well be exceeding this, and so Git doesn't evaluate renames to keep the log operation from taking too long. (Detecting renames is an O(n^2) operation, where n is the number of add/delete pairs that need to be considered, so the time taken to process each commit in a log operation looking for renames increases exponentially with the number of add/delete permutations.)

See the git-log manpage for more detailed descriptions of these options.

like image 94
cdhowie Avatar answered Sep 16 '22 14:09

cdhowie