是否可以在 Git 中移动/重命名文件并维护其历史记录? [英] Is it possible to move/rename files in Git and maintain their history?
问题描述
我想重命名/移动 Git 中的一个项目子树
I would like to rename/move a project subtree in Git moving it from
/project/xyz
到
/components/xyz
如果我使用普通的 git mv 项目组件
,那么 xyz 项目
的所有提交历史都会丢失.有没有办法移动它以保持历史记录?
If I use a plain git mv project components
, then all the commit history for the xyz project
gets lost. Is there a way to move this such that the history is maintained?
推荐答案
Git 检测重命名而不是通过提交持久化操作,因此无论您使用 git mv
还是 mv
没关系.
Git detects renames rather than persisting the operation with the commit, so whether you use git mv
or mv
doesn't matter.
log
命令接受一个 --follow
参数,它在重命名操作之前继续历史,即它使用启发式搜索类似的内容:
The log
command takes a --follow
argument that continues history before a rename operation, i.e., it searches for similar content using the heuristics:
http://git-scm.com/docs/git-log
要查找完整的历史记录,请使用以下命令:
To lookup the full history, use the following command:
git log --follow ./path/to/file
这篇关于是否可以在 Git 中移动/重命名文件并维护其历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!