如何将当前目录的所有文件移动到新目录中并保留历史记录.
我试过了:
git mv . old_app
Run Code Online (Sandbox Code Playgroud)
但我得到:
fatal: bad source, source=, destination=old_app/
Run Code Online (Sandbox Code Playgroud)
Jul*_*ian 32
我只是偶然发现了这个错误信息,显然解决方案非常简单.
但首先要记住的是有mv和git move.
正常的bash移动用法是:mv * ./subDir它只会产生警告,但仍会移动你的文件.
而git mv使用git mv * ./subDir将产生致命错误并中止移动:
fatal: can not move directory into itself, source=currentDir/subDir, destination=currentDir/subDir/subDir
使git mv工作的解决方案很简单:
git mv -k * ./subDir
该选项-k将简单地跳过所有会产生错误的操作.
fea*_*lly 12
您需要启用扩展全局,以便您可以使用正则表达式.
如果您在执行以glob为特色的命令之前使用bashshell类型shopt(shell选项)命令:
$ shopt -s extglob
Run Code Online (Sandbox Code Playgroud)
(~/.bash_profile如果你不想每次都输入这个,你也可以添加它)
然后您可以使用以下语法:
$ git mv ./!(exclude_me|exclude_me) ./destination_folder
Run Code Online (Sandbox Code Playgroud)
例如,如果这是您的文件夹结构:
root
??? aardvark
??? contrib
| ??? folder1
| ??? folder2
??? custom
| ??? folder1
| ??? folder2
??? elephant
??? hippopotamus
??? zebra
Run Code Online (Sandbox Code Playgroud)
然后在root目录中运行以下命令:
$ shopt -s extglob
$ git mv ./!(custom|contrib) ./contrib
Run Code Online (Sandbox Code Playgroud)
你最终会得到这个:
root
??? contrib
| ??? aardvark
| ??? elephant
| ??? folder1
| ??? folder2
| ??? hippopotamus
| ??? zebra
??? custom
??? folder1
??? folder2
Run Code Online (Sandbox Code Playgroud)
添加-n标志是否要进行测试运行并确保命令执行时没有错误:
$ git mv -n ./!(exclude_me|exclude_me) ./destination_folder
Run Code Online (Sandbox Code Playgroud)
添加-k标志以包含不受版本控制的文件:
$ git mv -k ./!(exclude_me|exclude_me) ./destination_folder
Run Code Online (Sandbox Code Playgroud)
如果使用zshshell,则按以下方式启用扩展globbing并用于^否定模式.
$ setopt extendedglob
$ git mv ^(exclude_me|exclude_me) ./destination_folder
$ git mv ^exclude_me ./destination_folder
Run Code Online (Sandbox Code Playgroud)
所以,我遇到了同样的问题,我的工作是什么
for file in $(ls | grep -v 'yourfolder'); do git mv $file yourfolder; done;
Run Code Online (Sandbox Code Playgroud)
raj*_*uGT -3
我认为,您所做的操作是无效的。
\n\n您无法将当前目录 (pwd) 移动.到当前目录内的其他目录。即使mv命令也不起作用。正如输出所说
mv: cannot move \xe2\x80\x98.\xe2\x80\x99 to \xe2\x80\x98someDir/.\xe2\x80\x99: Device or resource busy\nRun Code Online (Sandbox Code Playgroud)\n\n在 git mv 中使用 * 还表示
\n\ngit mv * someDir\nfatal: can not move directory into itself, source=curDir, destination=curDir/someDir\nRun Code Online (Sandbox Code Playgroud)\n\n上一级目录,选择需要移动到目标目录的目录。在这种情况下,您也无法将父目录移动到子目录中。可以将父目录内容/文件移动到目标目录,但不能移动到父目录本身。
\n| 归档时间: |
|
| 查看次数: |
14375 次 |
| 最近记录: |