如何查找其原始名称已知的重命名文件的新路径? [英] How to find the new path of a renamed file whose original name is known?

查看:158
本文介绍了如何查找其原始名称已知的重命名文件的新路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下用例:

我正在本地分支上工作,而重构已经在主分支上完成了.现在,某些文件(类)已被重命名和/或移动到了新位置.合并时,由于缺少类,我收到很多导入错误.

I'm working on my local branch while refactoring has been done on the main branch. Now some files (classes) have been renamed and/or moved to new locations. When merging i get lots and lots of import-errors due to missing classes.

--A--B--C--D--E-- (master)
   \           \
    F--G--H--I--J  (topic)

A中有我在F--G--H--I中使用的旧名称.

In A there are the old names wich i used in F--G--H--I.

B--C--D--E中,文件被重构,从而在E中产生新的文件名.这包括链式重命名,例如

In B--C--D--E the files are refactored resulting in new file names in E. This includes chained renames like

   B: path/to/File.java              
-> C: path/to/BetterName.java
-> D: better/package/BetterName.java 
-> E: final/package/FinalName.java

由于我分支上缺少重构,现在合并导致J中出现许多(编译)错误. (因为我仍然引用path.to.File而不是final.package.FinalName

Now merging results in J with many (compilation) errors due to the missing refactorings on my branch. (Because i still refer to path.to.File instead of final.package.FinalName

为了修复损坏的版本,我需要知道旧类的新名称.

In order to fix the broken build, i need to know the new names for the old classes.

是否存在git命令来获取已应用于特定文件的所有重命名?

Is there a git command to get all the renames that have been applied to a particular file?

推荐答案

Git应该找到文件的重命名.但是,如果文件在该文件中有50%或更多的行更改,它将不再被视为重命名.您可以根据需要更改此阈值.

Git should find the renames of the files. However, if the file has had 50% or more lines change in that file, it will no longer be considered a rename. You can change this threshold if you wish.

这是执行此操作的命令:

Here is the command to do it:

git log -M --diff-filter=R --stat

它只会显示您的重命名.如果要将阈值更改为默认值50%以外的其他值,可以将数字添加到M选项:

It will only show you the renames. If you want to change the threshold to something else other than the default 50%, you can just add the number to the M option:

git log -M90 --diff-filter=R --stat

仅在文件内容更改不超过10%时才将文件视为已重命名.

will only consider a file as renamed if the contents have changed by no more than 10%

更新:

要跳过所有中间步骤,请改用diff. Git将为您重新命名:

To skip all the intermediate steps, use diff instead. Git will follow the renames for you:

git diff -M --diff-filter=R --name-status ..master | cut -f2-

当您在主题分支上时.

然后您可以通过管道发送此命令,以执行一堆sed指令来调整参考.

You can then pipe this to make a bunch of sed instructions to adjust your references.

这篇关于如何查找其原始名称已知的重命名文件的新路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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