【问题标题】:Move files to root of git repo将文件移动到 git repo 的根目录
【发布时间】:2015-09-02 18:31:22
【问题描述】:

我需要将所有文件从文件夹“example”移动到 git repo 的根目录。我无法弄清楚它的命令。 有人可以帮忙吗? 谢谢

【问题讨论】:

标签: git git-bash


【解决方案1】:
git mv example/* .
git commit -m "moved example/* to root"

【讨论】:

  • 已经试过了,但它给出了以下结果:致命:错误来源,来源=示例/*,目的地=*
  • ls example | wc -l 的输出是什么?当“示例”为空时,我得到你的输出,我尝试git mv example/* .
  • 现在我明白我做错了什么。我将命令输入到 windows 终端,而不是 git bash 终端...我变老了。
【解决方案2】:

您需要使用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 编辑的文件,那么您也会遇到此错误消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-13
    • 2010-10-11
    • 2021-09-19
    • 1970-01-01
    • 2013-04-09
    • 2019-05-07
    • 2015-01-11
    • 1970-01-01
    相关资源
    最近更新 更多