我可以检查文件的两个版本之间的差异是否仅包含我添加的新前缀吗? [英] Can I check that the diff between two versions of a file solely contains a new prefix that I've added?

查看:74
本文介绍了我可以检查文件的两个版本之间的差异是否仅包含我添加的新前缀吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

作为将几个类抽象到一个接口的一部分,我不得不更改一个文件,该文件使用这些旧类之一现在将其指向接口字段。

As part work to abstract a few classes to one interface, I've had to changes a file which makes use of one of these old classes to now point it to the interface fields.

该文件以前看起来像这样(例如,经过简化)。

The file previously would have looked something like this (simplified for example).

public class Foo{

    public string RetrieveValue(MyModel model)
    {
        return model.Area.Street.Flat;
    }

    public string RetrieveOtherValue(MyModel model)
    {
        return model.Area.Shop;
    }

}

但现在看起来像这样。

But would now look like this.

public class Foo{

    public string RetrieveValue(MyModel model)
    {
        return model.Base_Area.Base_Street.Base_Flat;
    }

    public string RetrieveOtherValue(MyModel model)
    {
        return model.Base_Area.Base_Shop;
    }

}

问题

我可以轻松检查一下,这里唯一的变化是在各个地方都包含了 Base _ 吗?

Can I check easily that the only change here was the inclusion of Base_ in various places?

使用diff工具很容易看到这种规模,但是文件太大,以至于我不信任它。我正在使用的源代码控制是git,但如有必要,我很乐意使用其他工具。

It's easy to see on this scale with a diff tool, but the file big enough that I don't trust just eyeballing it. My source control in use is git but I'm happy to use other tools if necessary.

理想情况下,我也想忽略所有空白。

Ideally I'd like to ignore all sorts of whitespace, too.

推荐答案

我认为以下内容应该关闭:

I think the following should get close:

git diff --word-diff-regex=. > changes.txt
grep -oP '\+[^\+]+\+' changes.txt | tr -d '\+' | sort -u

在第一行中,做一个比较,然后将其写入文件。

第二行提取基于字符的更改,并删除 +。最后,将其排序并保留唯一值。我将上面的代码应用于您的示例,并得到以下结果:

In the first line, you make a diff which you write to a file.
The second line extracts the changes on character basis and removes the "+". In the end it is sorted and unique values are kept. I applied the above code to your example and got the following result:

Base_

这甚至可以用于更多文件或其他文件夹中已更改的文件。您仍然可以立即获得答案-但以防万一,分析需要花费更多时间。

This even works with more files or files which were changed in other folders. You still get the answer right away - but in case, analysis takes more time.

这篇关于我可以检查文件的两个版本之间的差异是否仅包含我添加的新前缀吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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