繁体   English   中英

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

[英]How do you move multiple files in 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

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

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

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

我使用 bash 循环:

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

只要工作目录中没有任何其他更改,最简单的方法就是自己移动它们,然后使用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

在 Windows (PowerShell) 中:

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

对我有用:

$ 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
#

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM