开发者

Changing subfolder name in git project without losing file history?

FYI, I'm pretty new to git, using mostly gitgui.

When I change the name of an already tracked folder containing already tracked files in my project, git sees all the files in the folder as new untracked files. How do I make开发者_高级运维 git understand that I only changed the name of the folder, so that I don't "lose" the history of the files contained in that folder?


Git doesn't care about your files or folders. There I said it. It tracks your content. After you move your files it'll show in git status as deleting a set of files/folders and a creation of files/folders. After your commit Git will detect that it's already seen this exact content and be able to follow not only the "files" and "folders" but even if you moved code from one file to another by the way it manages chunks.

Welcome to Git!


Git doesn't explicitly track moves/renames or copies. Instead, it detects them when it's asked to. Do the move, and run git diff -M.


Here are some examples to show that Git is really a content tracker:

  1. The -CCC option of git blame can find lines that have been moves across files and revisions, and associate the correct blame.
  2. The --find-copies-harder option of the git diff family, git format-patch, and git log illustrate the same point. On a related note, do run format-patch with atleast -C when sending of patches to projects.

Therefore, you don't have to tell Git explicitly about copies or moves: it will detect them automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜