使用Git记录文件复制操作 [英] Record file copy operation with Git

查看:127
本文介绍了使用Git记录文件复制操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用git-mv在git中移动文件时,状态显示文件已被重命名,即使我改变了一些部分,它仍然认为是几乎相同的东西(这是好的,因为它让我跟踪历史的)。



当我复制文件时,原始文件有一些历史记录,我想与新的副本关联。



我已经尝试移动文件,然后尝试在原始位置重新签出 - 一旦移动git将不允许我签出原始位置。



我试过做一个文件系统副本,然后添加文件 - git将其列为一个新文件。



有什么办法使git记录文件复制操作以类似的方式如何记录文件重命名/移动历史可以追溯到原始文件?

解决方案

Git不做重命名跟踪或复制跟踪,这意味着它不会记录重命名或副本。它做的是重命名和复制 检测 。您可以使用 -M来请求 git diff (和 git show )中的重命名检测选项( -C ),您可以通过 $ c>意味着 -M ),你可以请求所有文件中更昂贵的副本检测 - find-copies-harder -C -C (这意味着 -C ,意味着 -M )。请参阅 git-diff 联机帮助页。



您还可以将git配置为总是通过将 diff.renames 设置为布尔值true来进行重命名检测(例如 true 1 ),您也可以通过将 copy code> copies 。请参阅 git-config 联机帮助页。



检查 -l <​​/ code>选项 git diff 和相关的配置变量请注意, git log < pathspec> 在Git中的工作方式不同:这里< pathspec> 是路径分隔符集合,其中path可以是。它会过滤和简化历史之前重命名和复制检测功能。如果你想跟随重命名和副本,使用 git log --follow< filename> (目前有限,只适用于单个文件) em>


When I move a file in git using git-mv the status shows that the file has been renamed and even if I alter some portions it still considers to be almost the same thing (which is good because it lets me follow the history of it).

When I copy a file the original file has some history I'd like to associate with the new copy.

I have tried moving the file then trying to re-checkout in the original location - once moved git won't let me checkout the original location.

I have tried doing a filesystem copy and then adding the file - git lists it as a new file.

Is there any way to make git record a file copy operation in a similar way to how it records a file rename/move where the history can be traced back to the original file?

解决方案

Git does not do rename tracking nor copy tracking, which means it doesn't record renames or copies. What it does instead is rename and copy detection. You can request rename detection in git diff (and git show) by using the -M option, you can request additional copy detection in changed files by using the -C option (-C implies -M), and you can request more expensive copy detection among all files with --find-copies-harder or -C -C (which implies -C, which implies -M). See the git-diff manpage.

You can also configure git to always do rename detection by setting diff.renames to a boolean true value (e.g. true or 1), and you can request git to do copy detection too by setting it to copy or copies. See the git-config manpage.

Check also the -l option to git diff and the related config variable diff.renameLimit.


Note that git log <pathspec> works differently in Git: here <pathspec> is set of path delimiters, where path can be a (sub)directory name. It filters and simplifies history before rename and copy detection comes into play. If you want to follow renames and copies, use git log --follow <filename> (which currently is a bit limited, and works only for single file).

这篇关于使用Git记录文件复制操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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