How do you move multiple files in git?
I try:
git mv a.py b.py src/
and get
fatal: multiple sources for the same target, source=b.py, destination=src/b.py
Using the -n fla开发者_如何学JAVAg, like so git mv -n a.py b.py src/
gives me:
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
Am I doing something really stupid? I'm using git version 1.6.6.1
I use bash loop:
for FILE in src/*.h; do git mv $FILE include/; done
This has been fixed in the current master branch of git, it's in v1.7.0-rc0 but not in a release build yet.
http://git.kernel.org/?p=git/git.git;a=commit;h=af82559b435aa2a18f38a4f47a93729c8dc543d3
In the mean time the simplest thing to do is to either git mv
the files individually or to just use mv
and then update the index manually, e.g. with git add -A
if you have appropriate .gitignore
patterns.
In Windows (PowerShell):
foreach ($file in get-childitem *.py) { git mv $file.name ./src }
As long as there aren’t any other changes in the working directory, the simplest way is just to move them yourself and then use git add -A
. Behold:
$ 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
Works for me:
$ 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
#
精彩评论