Git:大规模重构保留更改日志 [英] Git: massive refactor keeping changes log

查看:63
本文介绍了Git:大规模重构保留更改日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在不丢失 Git 更改跟踪的情况下进行涉及移动和重命名多个目录的大规模重构?

Is it possible to do a massive refactor that involves moving and renaming many directories without losing Git change tracking?

推荐答案

git 可以很好地处理移动/重命名目录,但是要跟踪这些重命名的更改,您可能需要向正在使用的任何命令添加一些额外的参数,或者设置几个配置选项.

git copes fine with moving / renaming directories, but to track changes across these renames you may need to add some extra parameters to whatever command you're using, or set a couple of config options.

这样做的原因是 git 只存储每次提交时树的状态,而不是为了从一种状态移动到另一种状态而发生的更改.如果您的源代码树中有很多文件,那么您可能需要告诉 git 主动尝试查找任何重命名.同样,如果您对特定文件感兴趣,则需要明确告诉 git 搜索过去可能的重命名.

The reason for this is that git just stores the state of the tree at each commit rather than the changes that took place in order to move from one state to another. If you have many files in your source tree then you may need to tell git to actively try to find any renames. Similarly, if you're interested in a particular file, you'll need to tell git explicitly to search for possible renamings in its past.

举一个后者的例子,一个典型的例子是使用 git log -- filename 来检查特定文件的历史记录.为了告诉 git 在可能发生的任何重命名之前还查找其历史记录,您必须执行以下操作:

To give an example of the latter, a typical case is using git log -- filename for examining the history of a particular file. In order to tell git to also look for its history before any rename that might have occurred, you have to do:

git log --follow -- filename

再举一个例子,如果您的树中有很多文件,git log --stat 的有用输出可能不包括您的所有重命名或副本,因为它需要检查所有文件对要做到这一点.要强制 git 在使用 git loggit diff 时检测副本和重命名,您可以将配置选项 diff.renameLimit 设置为至少数字树中的文件,并将配置选项 diff.renames 设置为 copies - 这意味着检测副本重命名.

As another example, the useful output of git log --stat may not include all of your renames or copies if you have many files in your tree, since it needs to check all pairs of files to do that. To force git to detect copies and renames when using git log and git diff you can set the config option diff.renameLimit to at least the number of files in your tree, and set the config option diff.renames to copies - this means to detect copies and renames.

或者,如果您不想将这些设置为配置选项,您可以使用 -M-C 选项来git loggit diff.这些在 Jakub Narębski 对这个问题的回答中有更详细的描述:

Alternatively, if you don't want to set these as config options, you can use the -M or -C options to git log or git diff. These are described in more detail in Jakub Narębski's answer to this question:

这篇关于Git:大规模重构保留更改日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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