将项目移动到子目录中

时间:2012-10-11 14:46:13

标签: git

我在名为project的目录中有一个git存储库:

[~/project]$ ls
a  b  c

我想将所有内容移动到project目录的子目录中,所以它看起来像这样:

[~/project]$ ls
subdir
[~/project]$ cd subdir
[~/project/subdir]$ ls
a  b  c

通常git mv会起作用,但我想让它看起来好像从头开始就一直在对该子目录进行历史提交。有没有办法做到这一点?

1 个答案:

答案 0 :(得分:5)

filter-branch看起来像我想要的那样:

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

-d /tmp/whatever部分只是在tmpfs文件系统上运行命令,因此没有一堆磁盘IO。

(在极少数情况下,/tmp不会作为tmpfs挂载。您可以使用mount | grep tmp进行检查。)