Question
Does it make a difference if I move Git tracked files with the git mv
command as opposed to just moving the files with MS-DOS move
or the Windows Explorer?
Back in the Subversion days, it was necessary to use for example the TortoiseSVN SVN Move versioned files here
command to keep the history intact.
I would have expected it to work the same way in Git, but a test (see example below) showed that Git detects by itself that the file has been moved and that the history is kept intact.
So why use git mv
at all?
Example
C:\test>git init
C:\test>mkdir folder
C:\test>cd folder
C:\test\folder>echo "1" > file.txt
C:\test\folder>git add .
C:\test\folder>git commit -m "Initial commit"
C:\test\folder>echo "2" >> file.txt
C:\test\folder>git add .
C:\test\folder>git commit -m "Update file.txt"
C:\test\folder>move file.txt ..
C:\test\folder>cd ..
C:\test>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: folder/file.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
file.txt
no changes added to commit (use "git add" and/or "git commit -a")
C:\test>git add -A
C:\test>git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: folder/file.txt -> file.txt
C:\test>git commit -m "Moved file.txt with the move command"
The entire history has been retained despite not using git mv
and Git says that is has detected a renaming.
C:\test>git log --oneline --follow file.txt
6bd3c05 Moved file.txt with the move command
5b55aea Update file.txt
5b9b255 Initial commit
git add .
after a manual move, will this work? I'm asking for auto-generated html files through a static generator like pelican which reside on thegh-pages
branch. Since several new files are added/removed on each build, you can't be expected to separately run a git command for each file? – Rinna