1

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?

reto
  • 9,995
  • 5
  • 53
  • 52
Shoji Urashita
  • 826
  • 2
  • 11
  • 22
  • I do not want to use git move. I would like to use files under C1 and C2 as if they were under repo/C1 and repo/C2 from the beginning. – Shoji Urashita Feb 04 '15 at 11:49
  • Do you want to delete the directories A1, B1, A2 and B2 – gpullen Feb 04 '15 at 11:50
  • Yes, I would like to delete A1, B1, A2 and B2 as if they were not there from the beginning. I checked this, but could not work. http://stackoverflow.com/questions/3142419/how-can-i-move-a-directory-in-a-git-repo-for-all-commits – Shoji Urashita Feb 04 '15 at 11:52
  • If there is only one directory I can do like this. git filter-branch --subdirectory-filter Unfortunately. --subdirectory-filter supports only one directory. http://stackoverflow.com/questions/19954485/extract-multiple-directories-using-git-filter-branch – Shoji Urashita Feb 04 '15 at 14:54

3 Answers3

0
$ 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.

Shoji Urashita
  • 826
  • 2
  • 11
  • 22
0

The filter-branch command iterates through the whole history of your repo. You may get the No such file or directory error if the folder hasn't been existed from the beginning, and as mv returns with nonzero exit code, the whole iteration stops.

The simplest solution is to append || true to the filter command:

git filter-branch --tree-filter 'mv A1/B1/C1 . || true' HEAD

You will still receive the No such file or directory messages for the steps when the folder was nonexistent but at least the process will not stop immediately.

György Kőszeg
  • 17,093
  • 6
  • 37
  • 65
-1

just move them in terminal or file manager and commit changes.

pankijs
  • 6,531
  • 3
  • 16
  • 13
  • 2
    I need previous history. I would like to use C1 and C2 as if they were under repo from the begging. – Shoji Urashita Feb 04 '15 at 11:49
  • your previous history is saved in git. for example i have website coded in just html, recently deleted everything and made it as wordpress site, I can go back to html files with checkout any time I want. that is how version control works, you can delete, move files how you want, they will be in your history no matter what. – pankijs Feb 04 '15 at 11:54
  • 1
    I am pretty familiar with VCS. old: repo/A1/B1/C1/ddd.txt new: repo/C1/ddd.txt I would like to get a new repository as if ddd.txt was repo/C1/ddd.txt from the beginning. – Shoji Urashita Feb 04 '15 at 11:58