Changing the name of a subfolder in a 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 files without a trace. How to 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 this folder?

+4
source share
3 answers

Git does not care about your files or folders. I said that there. It tracks your content. After moving the files, it will appear in git status as deleting a set of files / folders and creating files / folders. After your git commit detects that it has already seen this exact content and will be able to track not only the “files” and “folders”, but even if you move the code from one file to another, as it controls the pieces.

Welcome to Git!

+6
source

Git does not explicitly track movement / rename or copy. Instead, he discovers them when they ask. Make a move and run git diff -M .

+2
source

Here are a few examples showing that Git is really a content tracker:

  • The -CCC option for the Git wiki can find lines that move through files and revisions and bind the correct fault.
  • The -find-copy-harder option of the Git diff, Git format-patch, and Git log families illustrates the same point. In this regard, note that run the patch file with atleast -C when sending patches to projects.

Therefore, you do not need to explicitly tell Git about copies or movements: it will automatically detect them.

+1
source

Source: https://habr.com/ru/post/1314126/


All Articles