Git mv does not work with Fatal: the source directory is empty

I would like to keep file history in a repo subfolder. But I need to rename the top level folder name. When I run 'git mv dirName newDirName I get "Fatal: the 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 save the file history in subfolders below? Or do I need to create a directory structure first and then move the files using the git mv command?

+17
git
source share
4 answers

I think that β€œFatal: source directory is empty” means that dirName is not under git control because it is not part of the source. For example, you can try "git status" to find out what can be controlled with git.

+25
source share

You should just tell git mv to skip any operation leading to a failure state

 git mv -k dirName newDirName 
+4
source share

Typically, the path name used in the git command is a relative path launched from the current directory.

So, for your question you need to check the following.

1) Whether dirName is a directory managed by git. you can use git ls-files

2) Will the dirName folder be under the current director.

+3
source share

This can happen on Windows if you use backslashes in the path to the source folder.

0
source share

All Articles