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?

4
  • 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. Feb 4, 2015 at 11:49
  • Do you want to delete the directories A1, B1, A2 and B2
    – gpullen
    Feb 4, 2015 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. stackoverflow.com/questions/3142419/… Feb 4, 2015 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. stackoverflow.com/questions/19954485/… Feb 4, 2015 at 14:54

3 Answers 3

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.

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.

-1

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

3
  • 2
    I need previous history. I would like to use C1 and C2 as if they were under repo from the begging. Feb 4, 2015 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 4, 2015 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. Feb 4, 2015 at 11:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.