git粘贴命令行_如何使用git检测复制和粘贴代码?

博客探讨了如何利用git-blame和git-log命令组合来检测代码中可能存在的复制和粘贴情况。通过找到引入新文件的提交,然后分析该提交与其父提交之间的差异,可以发现代码重复。作者好奇这种方法是否能用于git钩子以预防复制粘贴代码,但未深入解释如何实现。文章涉及代码质量、重构和git命令的高级用法。
摘要由CSDN通过智能技术生成

我只是再次阅读 git-blame

手册页,注意到这部分:

A particularly useful way is to see if an added file has lines created by copy-and-paste from existing files. Sometimes this indicates that the developer was being sloppy and did not refactor the code properly. You can first find the commit that introduced the file with:

git log –diff-filter=A –pretty=short — foo

and then annotate the change between the commit and its parents, using commit^! notation:

git blame -C -C -f $commit^! — foo

这听起来很有趣,但是我不太了解它是如何工作的,为什么.我想知道它是否可以用于git钩子来检测复制&粘贴代码.

一些git专家可能会解释使用上述git命令在一起的效果,以及是否可以使用这样的东西来使git显示是否有代码重复(可能通过使用git似乎在重命名文件时计算的“相似性索引” )?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值