filter-branch to remove extra directory

会有一股神秘感。 提交于 2019-11-28 11:10:06
dahlbyk

Figured it out based on a comment here. It seems to be an issue with how git-svn represents "empty" (directory-only) commits. It works fine if I start at a normal commit:

git filter-branch --index-filter \
    'git ls-files -s | sed "s-/trunk/-/-" |
        GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
            git update-index --index-info &&
     mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' 83df928c..HEAD

Hmm. I can't see anything wrong with what you're running, and it works fine for me in an example repository:

$ git init
Initialized empty Git repository in /Users/bcampbel/tmp/git-subdir/.git/
$ mkdir -p proj1/trunk
$ echo "hello" > proj1/trunk/test.txt
$ git add .
$ git commit -m "initial commit"
[master (root-commit) cd431f3] initial commit
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 proj1/trunk/test.txt
$ echo "foo" > proj1/trunk/another.txt
$ git add .
$ git commit -m "add a file"
[master 84139f2] add a file
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 proj1/trunk/another.txt
$ git filter-branch --index-filter \
>     'git ls-files -s | sed "s-/trunk/-/-" |
>         GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
>             git update-index --index-info &&
>      mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
Rewrite 84139f26c7921721190b3c5dd57e2b49a41034aa (2/2)
Ref 'refs/heads/master' was rewritten
$ ls proj1/
another.txt test.txt

It appears that for some reason, the index.new file did not get written out on your system, or could not be read by the mv command. I am not sure why this would be, but I wonder if it may be due to the fact that you're using msysgit on Windows. Do you have a Linux box or Mac that you could try it on?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!