Reputation: 11686
I have a git repository in a directory called project
:
[~/project]$ ls
a b c
I want to move everything into a subdirectory of the project
directory, so it look like this:
[~/project]$ ls
subdir
[~/project]$ cd subdir
[~/project/subdir]$ ls
a b c
Normally a git mv
would work, but I want to make it look as if the historical commits had always been made to that subdirectory from the beginning. Is there a way to do this?
Upvotes: 4
Views: 723
Reputation: 11686
Looks like filter-branch
does what I want:
git filter-branch --tree-filter \
'mkdir subdir; \
find -maxdepth 1 \
-not -name . \
-not -name .git \
-not -name subdir \
-print0 \
| xargs -0 -I{} mv {} subdir' \
-d /tmp/whatever -- --all
The -d /tmp/whatever
part is just so it runs the commands on a tmpfs filesystem so there isn't a bunch of disk IO.
(In rare cases, /tmp
won't be mounted as tmpfs. You can check with mount | grep tmp
.)
Upvotes: 5