Search code examples
gitgit-filter-branch

How can I move multiple directories in a Git?


There is a Git repository like this.

   repo/
      A1/
        B1/
          C1/
      A2/
        B2/
          C2/

I would like to have one like this.

   repo/
      C1/
      C2/

I don't need A1, B1, A2, B2 directories any more.

$ git filter-branch --tree-filter 'mv A1/B1/C1 .' HEAD
Rewrite xxxx(1/206)mv: cannot stat 'A1/B1/C1': No such file or directory
tree filter failed: mv A1/B1/C1 .

Any ideas?


Solution

  • $ git filter-branch --tree-filter 'mv A1/B1/C1 .' HEAD
    

    This code ends up with error like

    "mv: cannot stat 'A1/B1/C1': No such file or directory".

    But this code below worked correctly.

    $ git filter-branch --tree-filter "ls A1/B1 | xargs -i -t mv A1/B1/{} A1 | sh" HEAD
    

    I do not know why the first code does not work, but it seems ok. Thank you.