【发布时间】:2015-09-02 18:31:22
【问题描述】:
我需要将所有文件从文件夹“example”移动到 git repo 的根目录。我无法弄清楚它的命令。 有人可以帮忙吗? 谢谢
【问题讨论】:
-
这可以通过 google
git how to move files....在 10 秒内完成。
我需要将所有文件从文件夹“example”移动到 git repo 的根目录。我无法弄清楚它的命令。 有人可以帮忙吗? 谢谢
【问题讨论】:
git how to move files....在 10 秒内完成。
git mv example/* .
git commit -m "moved example/* to root"
【讨论】:
ls example | wc -l 的输出是什么?当“示例”为空时,我得到你的输出,我尝试git mv example/* .。
您需要使用git mv 命令。查看下面的命令和结果输出。这是在 ZShell 中完成的,但应该适用于 Bash 和其他。
/tmp/test
.:
total 4.0K
drwxrwxr-x 2 ray ray 4.0K Sep 2 03:22 example/
./example:
total 0
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file1.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file2.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file3.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file4.txt
➜ test git:(master) git mv example/* .
➜ test git:(master) ✗ gst
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: example/file1.txt -> file1.txt
renamed: example/file2.txt -> file2.txt
renamed: example/file3.txt -> file3.txt
renamed: example/file4.txt -> file4.txt
➜ test git:(master) ✗ ls -lR
.:
total 4
drwxrwxr-x 2 ray ray 4096 Sep 2 03:22 example
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file1.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file2.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file3.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file4.txt
./example:
total 0
➜ test git:(master) ✗ git commit -m "Moved example/* to project root"
[master 1999275] Moved example/* to project root
4 files changed, 0 insertions(+), 0 deletions(-)
rename example/file1.txt => file1.txt (100%)
rename example/file2.txt => file2.txt (100%)
rename example/file3.txt => file3.txt (100%)
rename example/file4.txt => file4.txt (100%)
➜ test git:(master)
确保您正在尝试移动 文件 而不是目录,这可能会导致该错误消息:
/tmp/test
total 8.0K
drwxrwxr-x 2 ray ray 4.0K Sep 2 03:29 ex/
drwxrwxr-x 2 ray ray 4.0K Sep 2 03:22 example/
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file1.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file2.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file3.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file4.txt
➜ test git:(master) git mv example ex
fatal: source directory is empty, source=example, destination=ex/example
最后但同样重要的是,确保目录中的文件已经被跟踪。如果您尝试 git mv 从未被 git added 和/或 git commited 编辑的文件,那么您也会遇到此错误消息。
【讨论】: