I need to move all files from folder "example" to the root of the git repo. I cannot figure out the command for it. Can anybody help? Thanks
Asked
Active
Viewed 1,861 times
0
-
1This could have been done in 10seconds by googleing `git how to move files`.... – ckruczek Sep 02 '15 at 10:03
-
http://githowto.com/moving_files – Burak Karakuş Sep 02 '15 at 10:04
-
Possible duplicate of [How can I move all git content one-level up in the folder hierarchy?](https://stackoverflow.com/questions/7130850/how-can-i-move-all-git-content-one-level-up-in-the-folder-hierarchy) – avs099 May 24 '19 at 23:10
2 Answers
2
git mv example/* .
git commit -m "moved example/* to root"
chelmertz
- 20,399
- 5
- 40
- 46
-
Tried this already, but it gives the following: fatal: bad source, source=example/*, destination=* – Androrider Sep 02 '15 at 10:11
-
What's the output of `ls example | wc -l`? I get your output when "example" is empty and I try `git mv example/* .`. – chelmertz Sep 02 '15 at 10:22
-
1Now I see what I did wrong. I typed the command to the windows terminal, not to the git bash terminal... I am getting older. – Androrider Sep 02 '15 at 11:00
0
You need to use the git mv command. Look at the commands and resulting output below. This was done in the ZShell, but should work on Bash and others.
/tmp/test
.:
total 4.0K
drwxrwxr-x 2 ray ray 4.0K Sep 2 03:22 example/
./example:
total 0
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file1.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file2.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file3.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file4.txt
➜ test git:(master) git mv example/* .
➜ test git:(master) ✗ gst
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: example/file1.txt -> file1.txt
renamed: example/file2.txt -> file2.txt
renamed: example/file3.txt -> file3.txt
renamed: example/file4.txt -> file4.txt
➜ test git:(master) ✗ ls -lR
.:
total 4
drwxrwxr-x 2 ray ray 4096 Sep 2 03:22 example
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file1.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file2.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file3.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file4.txt
./example:
total 0
➜ test git:(master) ✗ git commit -m "Moved example/* to project root"
[master 1999275] Moved example/* to project root
4 files changed, 0 insertions(+), 0 deletions(-)
rename example/file1.txt => file1.txt (100%)
rename example/file2.txt => file2.txt (100%)
rename example/file3.txt => file3.txt (100%)
rename example/file4.txt => file4.txt (100%)
➜ test git:(master)
Make sure that you're trying to move the files and not the directory, which could cause that error message:
/tmp/test
total 8.0K
drwxrwxr-x 2 ray ray 4.0K Sep 2 03:29 ex/
drwxrwxr-x 2 ray ray 4.0K Sep 2 03:22 example/
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file1.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file2.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file3.txt
-rw-rw-r-- 1 ray ray 0 Sep 2 03:22 file4.txt
➜ test git:(master) git mv example ex
fatal: source directory is empty, source=example, destination=ex/example
Last, but not least, make sure the files within the directory are already being tracked. If you try to git mv files that have never been git added and/or git commited, then you'll also run into this error message.
code_dredd
- 5,915
- 1
- 25
- 53