tags:

views:

35

answers:

3

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?

+1  A: 

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.

Novelocrat
+1  A: 

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!

Marco Ceppi
A: 

Hi,

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.

Ramkumar Ramachandra