How to do a git diff on moved/renamed file?

后端 未结 6 1482
温柔的废话
温柔的废话 2020-12-07 15:57

I moved a file using git mv. Now I would like to do a diff on the new file to compare it with the old file (with the old, now non-existent name).

How d

6条回答
  •  爱一瞬间的悲伤
    2020-12-07 16:38

    You need to use -M to let git autodetect the moved file when diffing. Using just git diff as knittl mentioned does not work for me.

    So simply: git diff -M should do it.

    The documentation for this switch is:

    -M[], --find-renames[=]
           Detect renames. If n is specified, it is a threshold on the similarity index 
           (i.e. amount of addition/deletions compared to the file’s size). For example, 
           -M90% means git should consider a delete/add pair to be a rename if more than
           90% of the file hasn’t changed.
    

提交回复
热议问题