是否可以在 Git 中移动/重命名文件并维护其历史记录? [英] Is it possible to move/rename files in Git and maintain their history?

查看:41
本文介绍了是否可以在 Git 中移动/重命名文件并维护其历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重命名/移动 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屋!

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