我有一个 git repo,目前我是唯一一个使用它的人。我想获取根文件夹下的所有文件和文件夹,并将它们放在一个新文件夹中。
当前结构:
主要-> 源代码 资源
新结构:
主要-> 应用程序1 源代码 资源
有没有办法让文件不会丢失它们的 git 历史记录?
我有一个 git repo,目前我是唯一一个使用它的人。我想获取根文件夹下的所有文件和文件夹,并将它们放在一个新文件夹中。
当前结构:
主要-> 源代码 资源
新结构:
主要-> 应用程序1 源代码 资源
有没有办法让文件不会丢失它们的 git 历史记录?
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.
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 就会(或应该)注意到移动已经发生。它将保留历史。
如果由于某种原因它没有--find-copies-harder
注意到移动,您可以尝试使用带有选项的 diff。