我遇到的情况是,有人在一个文件夹中启动了一个文件并进行了几次提交,然后在另一个文件夹中提交了该文件的副本并进行了更多提交。我想将此文件合并或合并为一个文件并保存历史记录。
第二份副本较新且正确,但位于错误的文件夹中。较旧的文件可以被较新的文件覆盖。
我可以复制并粘贴内容,但会丢失历史记录。
git rm <good-location/file>
git commit -m 'Removing bad file form good location'
git mv <bad-location/file> <good-location/file>
git commit -m 'Moving file to correct location'
完成此操作后,以下命令将显示适当的历史记录。
git log --follow -- <good-location/file>
使用-C<some number>%
参数增加跨副本跟踪文件的机会。有关,和更多详细信息diff
,请参见Git文档。log
blame
如果您使用的是GUI(例如Eclipse的Git插件),则可能会按预期工作。
您无法执行任何强制Git在提交时识别副本的操作。Git仅存储快照,但至少在命令行后,在事实启发式之后就非常出色。
一些示例用法和输出:
$ git log --format="%h" master.. --name-status -M100% --follow -- temp3
0d15571
R100 temp10 temp3
e55bab3
M temp10
6f16545
M temp10
0a849e3
M temp10
1a06161
C100 temp3 temp10
95c8a20
A temp3
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句