Git mv fails with Fatal: source directory is empty

Viewed 24172

I would like to maintain history of files within a sub-folder of a repo. But I need to rename the top level folder name. When I run 'git mv dirName newDirName I get 'Fatal: source directory is empty;'

My source directory has the following structure:

gitRepoDir
--.git
--Source 
--  -DirLevel2 
--   --DirLevel3 
--     --DirLevel4 
--       --DirLevel5 
+++       --DirNameToRename 
+++         --sub1dir 
+++           --File 
+++         --sub2dir 
+++           --File 
+++         --sub3dir 
+++           --File 
+++           --File 
+++         --sub4dir 
+++           --File

Is there a way to rename the top level folder and maintain history of the files in the below subfolders? Or do I need to create the directory structure first then move the files with the git mv command?

5 Answers

you should just tell git mv to skip any operation leading to failure condition

git mv -k dirName newDirName

In my case is really what that error message source directory is empty indicates, i.e. empty source directories can't be commit unless I added .gitignore file as dummy file in that directories. Only after that I can git mv that directories.

This can happen on Windows if you use backslash in the path for the source folder.

Related