Git mv 因致命而失败:源目录为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35906272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:51:03  来源:igfitidea点击:

Git mv fails with Fatal: source directory is empty

git

提问by koderiter

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;'

我想在存储库的子文件夹中维护文件的历史记录。但我需要重命名顶级文件夹名称。当我运行 'git mv dirName newDirName 我得到'致命:源目录为空;'

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?

有没有办法重命名顶级文件夹并维护以下子文件夹中文件的历史记录?还是我需要先创建目录结构,然后使用 git mv 命令移动文件?

回答by Freedom

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.

我认为,“致命:源目录为空;”意味着 dirName 不受 git 控制,因为它不是源的一部分。例如,您可以尝试“git status”,以找出 git 可以控制的内容。

回答by Mirco Ellmann

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

你应该告诉 git mv 跳过任何导致失败条件的操作

git mv -k dirName newDirName

回答by gzh

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

通常,git 命令中使用的路径名是从当前目录开始的相对路径。

So for your question, followings should be checked.

因此,对于您的问题,应检查以下内容。

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

1)dirName是否是git管理的目录。你可以使用命令git ls-files

2) Whether dirName folder is under current director.

2) dirName 文件夹是否在当前目录下。

回答by NateS

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

如果在源文件夹的路径中使用反斜杠,这可能会在 Windows 上发生。