如何在移动/重命名文件上做一个git diff? [英] How to do a git diff on moved/renamed file?

查看:139
本文介绍了如何在移动/重命名文件上做一个git diff?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 git mv 移动了一个文件。现在我想对新文件进行比较,以便与旧文件(使用旧的,现在不存在的名称)进行比较。



我该怎么做?

解决方案

您需要使用-M让git自动检测移动后的文件。使用 git diff ,因为knittl提到的不适用于我。

简单地说: git diff -M 应该这样做。



这个开关的文档是:

  -M [< n>], - 查找重命名[= n]] 
检测重命名。如果指定了n,则它是相似性指数
的阈值(即与文件大小相比的添加/删除量)。例如,
-M90%表示git应该将一个删除/添加对视为重命名,如果超过
90%的文件没有改变。


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 do I do this?

解决方案

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[<n>], --find-renames[=<n>]
       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.

这篇关于如何在移动/重命名文件上做一个git diff?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆