filter-branch --index-filter always failing with “fatal: bad source”

前端 未结 2 502
野趣味
野趣味 2020-12-11 03:56

So, I am trying to rename a folder in my repository using git filter-branch --index-filter, but I always end up with a \"fatal: bad source\" error.

The

相关标签:
2条回答
  • 2020-12-11 04:19

    git mv is not really appropriate in an --index-filter clause. Since --index-filter does not check out each commit it's rewriting into the working directory, and git mv operates on the working directory (in addition to the index), using git mv in --index-filter will not accomplish what is expected. Use a --tree-filter instead. (It might be possible to accomplish this still with --index-filter by using git update-index instead, but I don't have that available off the top of my head).

    0 讨论(0)
  • 2020-12-11 04:34

    As twalberg points out in his answer, git mv doesn't just access the index, it also access the disk. That's probably the reason why it doesn't work.

    I didn't want to use the slow --tree-filter so I tried to change the sample from the git filter-branch man page that shows how to move the complete repository into a subfolder.

    The result is this - and it actually works ;-)

    git filter-branch --index-filter '
    git ls-files -s | \
    sed "s-\(\t\"*\)my_file.txt-\1your_file.txt-" | \
    GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && \
    mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"
    ' HEAD
    
    0 讨论(0)
提交回复
热议问题