Reputation:
I am on windows 7 and have this simple structure
+ gitroot
|- someDir
|-- lots
|-- of
|-- other
|-- stuff
And I want to move everything in someDir into gitroot.
This, and some of its variations, do not work
gitroot > git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
gitroot > git --version
git version 2.9.2.windows.1
gitroot > git mv someDir\* .
fatal: bad source, source=someDir/*, destination=*
gitroot > git mv someDir/* .
fatal: bad source, source=someDir/*, destination=*
gitroot > git mv someDir/* ./ -k
The last one does not throw an error, but also does not do anything to my filesystem. I also tried to write out the paths completely with no success.
I don't know what gits problem is and it is bad at communicating it to me.
edit: I found the reason why someDir/* is not working. The shell I am using is not globbing and therefor git, rightfully so, expects to move a file named "someDir/*" which does not exist.
Upvotes: 0
Views: 4005
Reputation: 38619
The help for git mv
says:
it renames , which must exist and be either a file, symlink or directory
someDir\*
is not an existing file, symlink or directory, except if you actually have a file, symlink or directory named like that. That is exactly what the error tells you. The source is not an existing file, symlink or directory.
To make it work you could either do
mv someDir/* . && git add .
or execute it in Git Bash which already does the expanding of the *
, but then you need
git mv somedir/* somedir/.* .
as in bash *
does not exand hidden files (i. e. files starting with .
).
Alternatively you can also manually expand the files and move them separately like
git ls-tree --name-only @ gitspindle/ | xargs -ri git mv {} .
Upvotes: 2
Reputation: 45659
I believe the problem is that git
is expecting your shell to expand the *
, which is not happening. If you use git bash, it should. Or you could try manually listing out the directories to be moved, but it sounds like there's a lot of them so that may not be good.
A simple work-around, as noted in the comments, is to move the files using OS commands instead of git, and then do a git add .
. That's actually all that git mv
does anyway (for which reason I never bother with git mv
. (EDIT: To clarify, that's all it's doing in this case. There are situations, like submodules, where git mv
offers some nice automation of house-keeping details.)
In comments you expressed concern about losing history. The truth is, no matter whether you use git mv
or not, git records the change as "file at old path deleted; new file at new path". It attempts to infer after the fact that this was really "file moved from old path to new path" and has just as much chance of inferring this correctly no matter which command you use to do the move.
Upvotes: 2