lurscher lurscher - 3 months ago 13
Git Question

git command to move a folder inside another

I have created a folder

common
with a bunch of source files and folders.

Now I want to move the
common
folder into the
include
folder so it looks like
include/common


I tried these:

1)
git add include


2)
git mv common/ include/


but it fails with this error

fatal: bad source, source=myrepo/common, destination=myrepo/include


3) I tried git mv common/ include/common but I get the same error

Any idea how to achieve this?

Answer

One of the nicest things about git is that you don't need to track file renames explicitly. Git will figure it out by comparing the contents of the files.

So, in your case, don't work so hard:

$ mkdir include
$ mv common include
$ git rm -r common
$ git add include/common

Running git status should show you something like this:

$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   renamed:    common/file.txt -> include/common/file.txt
#