Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
767 views
in Technique[技术] by (71.8m points)

git - filter-branch to remove extra directory

I'm migrating several Subversion repositories to Git, but they were set up a bit weird: the standard trunk/branches/tags structure lives within several subdirectories of the repository. /branches and /tags are both empty, so the git-svn import ended up with only the trunk directories.

svn/
  proj1/
    trunk/
      src/
  proj2/
    trunk/
      src/

I would like to use git filter-branch to remove the extra trunk folders but leave the rest intact:

svn/
  proj1/
    src/
  proj2/
    src/

Based on the last example in the documentation, this is what I have so far:

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

It seems to me that the sed is doing its job, as this input:

100644 fa3dcf79717e9aca85ad745078a2fb2a2ce2b900 0       proj1/trunk/src/file1.txt

Produces this output:

100644 fa3dcf79717e9aca85ad745078a2fb2a2ce2b900 0       proj1/src/file1.txt

However, when I run the whole command, I get the following error:

Rewrite e00c119cfb755f741dc0e17c36d36bc2ddd27562 (1/42)mv: cannot stat `/c/dev/R
epo/.git-rewrite/t/../index.new': No such file or directory
index filter failed: 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"

Any ideas? I'm using git version 1.7.3.1.msysgit.0 on Windows.

Update: Now using git version 1.9.0.msysgit.0, a similar situation yields a different error (note .git-rewrite does not exist before executing the command):

rm: cannot remove `c:/Path/to/svn/.git-rewrite/revs': Permission denied
rm: cannot remove directory `c:/Path/to/svn/.git-rewrite': Directory not empty

The same fix ultimately worked.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...