你如何在git中移动多个文件?

时间:2010-02-06 10:56:52

标签: git

我试试:

git mv a.py b.py src/

并获取

fatal: multiple sources for the same target, source=b.py, destination=src/b.py

使用-n标志,如此git mv -n a.py b.py src/ 给了我:

Checking rename of 'a.py' to 'src/b.py'
Checking rename of 'b.py' to 'src/b.py'
fatal: multiple sources for the same target, source=b.py, destination=src/b.py

我做的事真的很蠢吗?我正在使用git版本1.6.6.1

5 个答案:

答案 0 :(得分:25)

我使用bash循环:

for FILE in src/*.h; do git mv $FILE include/; done

答案 1 :(得分:24)

这已在git的当前主分支中修复,它在v1.7.0-rc0中,但尚未在发布版本中修复。

http://git.kernel.org/?p=git/git.git;a=commit;h=af82559b435aa2a18f38a4f47a93729c8dc543d3

同时,最简单的方法是单独git mv文件或仅使用mv然后手动更新索引,例如如果您有适当的git add -A模式,请使用.gitignore

答案 2 :(得分:14)

只要工作目录中没有任何其他更改,最简单的方法就是自己移动它们然后使用git add -A。看哪:

$ ls
a.py b.py
$ mkdir src
$ mv *.py src
$ git status
# Changed but not updated:
#       deleted:    a.py
#       deleted:    b.py
# Untracked files:
#       src/
$ git add -A
$ git status
# Changes to be committed:
#       renamed:    a.py -> src/a.py
#       renamed:    b.py -> src/b.py

答案 3 :(得分:10)

在Windows(posh~git)中:

foreach ($file in get-childitem *.py) { git mv $file.name ./src }

答案 4 :(得分:9)

适合我:

$ git --version
git version 1.6.4.1
$ mkdir foo
$ cd foo
$ git init
Initialized empty Git repository in /home/wich/foo
$ touch a b c d
$ git add a b c d
$ git commit -m "foobar"
[master (root-commit) 11051bd] foo
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a
 create mode 100644 b
 create mode 100644 c
 create mode 100644 d
$ mkdir bar
$ git mv a b c d bar
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    a -> bar/a
#       renamed:    b -> bar/b
#       renamed:    c -> bar/c
#       renamed:    d -> bar/d
#
相关问题