tags:

views:

637

answers:

4

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

+1  A: 

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
jleedev
I can't say it's good, but I've never used `git rm` - just move the files myself and add tell `git` to add them later. The good thing is, `git` does recognize them as the same files.
phunehehe
+1  A: 

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
#
wich
That's weird, it doesn't work in 1.6.6 for me.
jleedev
I'll try with a newer version
wich
+4  A: 

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.

Charles Bailey
Thanks good to know
wich
I had missed -A as a switch to Add, very useful :)
Pondidum
+1  A: 

I use bash loop:

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