Git -mv show file removed
When I run git-mv file1 file2
I can move the file from file1
to file2
as I expected. Sometimes, however, mine git status
gives me an "odd" output.
When I run git-mv f1 f2
then git status
:
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# renamed: f1 -> f2
What I would expect. At the same time, after I committed f2
, I get:
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: f1
This usually happens after I have committed a new file. I don't know why this is happening - it seems like it happens by accident (because usually I get the message renamed: f1->f2
as I expect).
I would like to know why I sometimes get messages that I deleted the file after launching git mv
, and what steps I would follow to create it - I just tried to reproduce and got renamed:..
; but 10 minutes ago I got deleted:...
in a file that I git-mv
edited 10 minutes before. This really confuses me.
source to share
Git doesn't keep track of movements in file history like Subversion: history just stores the contents and git log
& c. look at the contents of the file and what has changed to determine if the change was a rename. So it's git mv f1 f2
equivalent to:
mv f1 f2
git rm f1
git add f2
Removing f1 and adding f2 are completely different changes as far as Git is concerned, so if you're doing now git commit f2
, you're only committing adding f2, and removing f1 is still uncommitted changes. To make sure you have committed both changes, do git commit
no arguments to commit everything, or git commit f1 f2
to commit only changes to these two files, or use git commit --interactive
or some other tool to edit the index in a more complex way. (An index is a list of "changes to be made".)
source to share