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

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

问题描述

我想重命名/移动Git中的项目子树,将它从

I would like to rename/move a project subtree in Git moving it from

/project/xyz

/components/xyz

如果我使用普通的 git mv project components ,那么 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命令使用 - 遵循参数,该参数在重命名操作之前会继续历史记录,即使用启发式方法搜索相似的内容:

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天全站免登陆