Git可以重构我的文件夹而不会丢失历史记录吗? [英] Can Git restructure my folders without losing history?
问题描述
我目前有一个git repo,我是唯一使用它的人。
我想将根文件夹下的所有文件和文件夹放在一个新文件夹中,例如:
当前root desc
main - >
src
res
新根
main - >
app1
src
res
如何在git窗口中完成而不会丢失我的历史记录?
TL; DR
继续:移动文件和目录。只要确保您不会像目录重组那样对文件进行任何编辑。
为什么有效
Git是内容跟踪器,而不是文件跟踪器。如果您移动/重命名文件,但不对这些文件的内容进行其他更改,那么Git只是
实际重命名检测由区分blob和树,并在文件之间寻找可配置的相似百分比。这意味着Git并不真正存储移动或直接重命名;它根据提交之间的差异计算它们。
所有这一切的结果是,您的历史记录不受特定文件名或目录结构的束缚。这对于大多数使用情况非常有效,但与像 Bazaar 这样将系统重命名为一流操作的系统形成鲜明对比。
I got a git repo current I'm the only one using it. I want to take all files and folder under root folder and put it in a new folder for example:
current root desc
main -> src res
new root
main -> app1 src res
How can I do it in git on windows without losing my history?
TL;DR
Go ahead: move your files and directories around. Just make sure you don't make any edits to files in the same commit as your directory restructuring.
Why It Works
Git is a content tracker, not a file tracker. If you move/rename files, but make no other changes to the content of those files, then Git just rewrites the tree objects. The file blobs are not changed by directory operations; directory location information is stored separately in tree objects.
Actual rename detection is handled by diffing the blobs and trees, and looking for a configurable percentage of similarity between files. This means that Git doesn't really store moves or renames directly; it computes them from differences between commits.
The upshot of all this is that your history is not tied to a particular filename or directory structure. This works really well for most use cases, but stands in contrast to systems like Bazaar that track renames as first-class operations.
这篇关于Git可以重构我的文件夹而不会丢失历史记录吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!