How do you move multiple files in git?

Viewed 42375

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 flag, 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

5 Answers

I use bash loop:

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

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