Lost git history after reorganizing project folder

If you want to move folders around in git, you can use git mv.

I had a bunch of folders in the root of my repository, and wanted to move them into two subdirectories, so I created the two new directories using **mkdir.

Then I moved files and folders one at a time into the new directories like this:

git mv folder1/ newDirectory1/
git mv file1.txt newDirectory2/

etc.

I had a case where I wanted to rename one of the directories to src and I did it like this:

git mv folder2 newDirectory1/src

This resulted in a set of files that looked like this:

repository/
   newDirectory1/
      folder1/
      src/
   newDirectory2/
      file1.txt

After I was finished, I created a new branch called "reorganized" so I wouldn't interfere with work another developer was doing in the master branch. He continued to work on the files, and as he pushed new changes to master, I pulled and merged the changes into my branch, and everything worked as I had hoped. Files that had been moved were referenced properly from their original locations, and received their commits.


In Git there's no the concept of file move.

Some tools, like GitHub, consider a commit containing a file named X that has been deleted and a file named X that has been created a file move.

According to Linus Torvalds, file move is just a special case of refactoring; for this reason Git will not treat it differently. Handling of this special case, like many others, is left to higher-level tools (such as frontends).

For more info on this topic, check this answer from Linus Torvalds.


Did you try settings the config diff.renames?

diff.renames

Tells git to detect renames. If set to any boolean value, it will enable basic rename detection. If set to "copies" or "copy", it will detect copies, as well.

Note: to follow history of a single file across renames, you need to use "git log -p --follow file".


As far as I see it you want:

git log --follow some_file.cpp

See http://git-scm.com/docs/git-log for details. I am not sure if that is what you want; but in case of git, git tracks content not files. The problem is that determining that information is really expensive and it is assumed that normally you don't need it...