Reputation: 1070
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
Upvotes: 0
Views: 2918
Reputation: 6095
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 add
ed and/or git commit
ed, then you'll also run into this error message.
Upvotes: 0