Che sia finestra o unix, git mv fondamentalmente combina tre azioni:
- uno spostamento del file system
- a git delete del file originale
- un git aggiunto del nuovo file.
Quindi, senza git rm, si potrebbe fare (questo è Unix / OSX ma i passaggi sono simili in Windows a meno che non si usi l'emulatore di terminale cygwin e quindi si possa probabilmente):
$ mv newfile movedfile
$ git status
On branch master
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: newfile
Untracked files:
(use "git add <file>..." to include in what will be committed)
movedfile
no changes added to commit (use "git add" and/or "git commit -a")
$ git rm newfile
rm 'newfile'
$ git add movedfile
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: newfile -> movedfile
$ git commit -m"renamed"
[master 46332e4] renamed
1 file changed, 0 insertions(+), 0 deletions(-)
rename newfile => movedfile (100%)
$ git status
On branch master
nothing to commit, working directory clean
mentre con git rm basta fare:
$ git mv newfile2 renamed_newfile2
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: newfile2 -> renamed_newfile2
$ git commit -m"renamed"
[master 8d1e296] renamed
1 file changed, 0 insertions(+), 0 deletions(-)
rename newfile2 => renamed_newfile2 (100%)
$ git status
On branch master
nothing to commit, working directory clean