【Git】 fatal: not under version control, source=A.txt, destination=B.txt
Gitで表題のようなエラーが出た。
ファイル名をチェックすると、ファイル名の一部が大文字小文字で異なっていた。 これは git を介さずにファイル名を変更したためとのこと[1]。
解決法には以下の2つがある。
- 元のファイル名に戻す。
- ファイル名変更をgitに伝える。
ここでは後者の方法を提示する。 手順は次の通りである。
- 元のファイル名でgit mv コマンドを実行する。
> ls a.txt > mv a.txt A.txt > ls A.txt > git mv A.txt B.txt fatal: not under version control, source=A.txt, destination=B.txt > ls A.txt > git mv a.txt B.txt > ls B.txt
あるいは、ファイル名自体を変更する方法もあるが、手間なのでお勧めはしない。
> ls a.txt > mv a.txt A.txt > ls A.txt >ls A.txt > mkdir dirB > git mv *.txt dirB fatal: not under version control, source=A.txt, destination=dirB/A.txt > mv A.txt _A.txt >ls _A.txt > git add . > git commit -m "rename temp filename" > mv _A.txt A.txt >ls A.txt > git add . > git commit -m "rename true filename" > git mv *.txt dirB > cd dirB > ls A.txt
参考資料
[1] rcmdnk.github.io