Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git mv fails with Fatal: source directory is empty

Tags:

git

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?

like image 781
koderiter Avatar asked Mar 10 '16 02:03

koderiter


People also ask

What is git MV?

We use the git mv command in git to rename and move files. We only use the command for convenience. It does not rename or move the actual file, but rather deletes the existing file and creates a new file with a new name or in another folder.

How do I move a directory in git?

Set the new URL as the origin of the current directory. This is the same directory where you have filtered code from the previous git repository. Next, verify that the Git origin URLs have been updated in the current directory. Finally, Push all the files to the new repository.


3 Answers

I think it, 'Fatal: source directory is empty;', means dirName is not under git control because it's not part of source. For example, you can try "git status", to figure out whatever can be controlled by git.

like image 84
Freedom Avatar answered Sep 30 '22 06:09

Freedom


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

git mv -k dirName newDirName
like image 21
Mirco Ellmann Avatar answered Sep 29 '22 06:09

Mirco Ellmann


Usually, the pathname used in git command is a relative path started from current directory.

So for your question, followings should be checked.

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

2) Whether dirName folder is under current director.

like image 42
gzh Avatar answered Sep 27 '22 06:09

gzh