Gitでファイルの名前を変更するときは、変更をコミットし、名前の変更を実行してから、名前を変更したファイルをステージングする必要があることを読みました。Gitは、ファイルを新しい追跡されていないファイルとして表示するのではなく、コンテンツからファイルを認識し、変更履歴を保持します。
しかし、今夜これを行うと、結局はに戻りましたgit mv
。
> $ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index.html
#
Finderでスタイルシートの名前をからiphone.css
に変更しましたmobile.css
:
> $ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index.html
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: css/iphone.css
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# css/mobile.css
そのため、Gitは、CSSファイルを1つ削除し、新しいファイルを追加したと見なします。それは私が望むものではありません。名前の変更を元に戻し、Gitに作業を任せましょう。
> $ git reset HEAD .
Unstaged changes after reset:
M css/iphone.css
M index.html
私は始めたところに戻っています:
> $ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: index.html
#
git mv
代わりに使用しましょう:
> $ git mv css/iphone.css css/mobile.css
> $ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: css/iphone.css -> css/mobile.css
#
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: index.html
#
私たちは元気そうです。では、Finderを使用したときに、Gitが初めて名前の変更を認識しなかったのはなぜですか?