Manipulando Renomeação de Arquivos no Git

Eu li isso quandorenomeando arquivos no git, você deve confirmar as alterações, renomear e preparar o arquivo renomeado. O Git reconhecerá o arquivo a partir do conteúdo, em vez de vê-lo como um novo arquivo não rastreado, e manterá o histórico de alterações.

No entanto, fazendo exatamente isso hoje à noite, acabei revertendo paragit mv.

> $ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   index.html
#

Renomeie minha folha de estilo no Finder deiphone.css paramobile.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

Então o git agora acha que excluí um arquivo CSS e adicionei um novo. Não é o que eu quero, vamos desfazer a renomeação e deixar o git fazer o trabalho.

> $ git reset HEAD .
Unstaged changes after reset:
M   css/iphone.css
M   index.html

Voltar para onde eu comecei.

> $ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   index.html
#

Permite usargit mv em vez de.

> $ 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
#

Parece que estamos bem. Então, por que o git não reconheceu o nome da primeira vez que usei o Finder?

questionAnswers(11)

yourAnswerToTheQuestion