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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…