GIT复制文件保留历史 [英] GIT copy file preserving history

查看:829
本文介绍了GIT复制文件保留历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有点混乱的问题在GIT。
假设我有一个文件 dir1 / A.txt committed并且git保存了提交的历史



现在我需要(由于某些原因)将文件复制到 dir2 / A.txt (不移动,但复制)。
我知道有一个 git mv 命令,但我需要 dir2 / A.txt dir1 / A.txt dir1 / A.txt 相同的提交历史仍保留在那里。 p>

我不打算更新 A.txt 一旦副本创建和所有未来的工作将完成 dir2 / A.txt



我知道这听起来很混乱,我会补充说这种情况是基于java模块(mavenized项目),我们需要创建一个新版本的代码,以便我们的客户将有能力在运行时有2个不同的版本,第一个版本将被删除,最终当对齐将完成。
我们可以使用maven版本当然,我只是新手在GIT和好奇的git可以提供这里。

解决方案

与subversion不同,git没有每个文件的历史记录。如果查看提交数据结构,它只指向此提交的先前提交和新的树对象。没有显式信息存储在提交对象中哪些文件被提交更改;也不是这些更改的性质。



检查更改的工具可以基于启发式检测重命名。例如。 git diff有选项-M打开重命名检测。所以在重命名的情况下,git diff可能会显示一个文件已被删除,另一个文件被创建,而git diff -M实际上将检测移动并显示相应的更改(参见man git difffor详细信息)。



所以在git中这不是你如何提交更改,而是如何查看已提交的更改。


I have a somewhat confusing question in GIT. Lets say, I have a file dir1/A.txt committed and git preserves a history of commits

Now I need (for some reasons) to copy the file into dir2/A.txt (not move but copy). I know that there is a git mv command but I need dir2/A.txt to have the same history of commits as dir1/A.txt, and dir1/A.txt to still remain there.

I'm not planning to update A.txt once the copy is created and all the future work will be done on dir2/A.txt

I know it sounds confusing, I'll add that this situation is on java based module (mavenized project) and we need to create a new version of code so that our customers will have the ability to have 2 different versions in runtime, the first version will be removed eventually when the alignment will be done. We can use maven versioning of course, I'm just newbie in GIT and curious about what git can provide here.

解决方案

Unlike subversion, git does not have a per-file history. If you look at the commit data structure, it only points to the previous commits and the new tree object for this commit. No explicit information is stored in the commit object which files are changed by the commit; nor the nature of these changes.

The tools to inspect changes can detect renames based on heuristics. E.g. "git diff" has the option -M that turns on rename detection. So in case of a rename, "git diff" might show you that one file has been deleted and another one created, while "git diff -M" will actually detect the move and display the change accordingly (see "man git diff" for details).

So in git this is not a matter of how you commit your changes but how you look at the committed changes later.

这篇关于GIT复制文件保留历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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