Can Git restructure my folders without losing history?

前端 未结 3 1821

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<

3条回答
  •  清歌不尽
    2020-12-08 03:18

    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.

提交回复
热议问题