filter-branch --index-filter始终以“致命:不良源”失败 [英] filter-branch --index-filter always failing with "fatal: bad source"
问题描述
git filter-branch --index-filter
来重命名我的资料库中的一个文件夹,但我总是以致命的:坏的源代码错误。使用文件而不是文件夹,可以很容易地在测试存储库中演示此问题。
准备:
$ git init
$ echo whatever>>> my_file.txt
$ git add。
$ git commit -minitial
$ echo whatever2>> my_file2.txt
$ git add。
$ git commit -msecond
现在,我正在尝试更改 my_file.txt
至 your_file.txt
:
$ git filter-branch --index-filter'git mv my_file.txt your_file.txt'HEAD
但它不起作用:
重写dac9a2023bdf9dd0159fab46213d9e1342ae9f75(1/2)致命:不良来源,来源= my_file.txt,destination = your_file.txt
索引过滤失败:git mv my_file.txt your_file.txt
然而,正常执行的 git mv
命令正常工作没有问题:
$ git mv my_file.txt your_file.txt
$ git status
#分支master
#要提交的更改:
#(使用git reset HEAD< file> ...停用)
#
#改名为:my_file.txt - > your_file.txt
#
我相信,我错过了一些必要的东西 - 但是是这样吗?
正如twalberg在他的回答中指出的那样,git mv不仅访问索引,还访问磁盘。这可能是它无法正常工作的原因。
我不想使用缓慢的 - tree-filter
,所以我尝试从 git filter-branch
手册页中更改示例,以显示如何将整个存储库移动到子文件夹中。
结果就是这样 - 它确实有效; - )
$ b
git filter-branch --index-filter'
git ls-files -s | \
seds \\ \\(\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
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 problem is easily demonstrated on a test repository using a file instead of a folder.
Preparation:
$ git init
$ echo whatever >> my_file.txt
$ git add .
$ git commit -m "initial"
$ echo whatever2 >> my_file2.txt
$ git add .
$ git commit -m "second"
Now, I am trying to change my_file.txt
to your_file.txt
:
$ git filter-branch --index-filter 'git mv my_file.txt your_file.txt' HEAD
But it doesn't work:
Rewrite dac9a2023bdf9dd0159fab46213d9e1342ae9f75 (1/2)fatal: bad source, source=my_file.txt, destination=your_file.txt
index filter failed: git mv my_file.txt your_file.txt
However, the very same git mv
command executed normally works without problems:
$ git mv my_file.txt your_file.txt
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: my_file.txt -> your_file.txt
#
I am sure, I am missing something essential here - but what is it?
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
这篇关于filter-branch --index-filter始终以“致命:不良源”失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!