Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-mv showing file deleted

Tags:

git

When I run git-mv file1 file2, I get the file moved from file1 to file2 as I'd expect. Sometimes, though, my git status gives me '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

That's what I'd expect. Other times, though, after I've committed f2, I get:

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage) 
#
#   deleted:    f1

This generally happens after I've committed the new file. I don't know why it happens - it seems to occur at random (because generally I get the renamed: f1->f2 message, like I'm expecting).

I'd like to know why I sometimes get messages saying I've deleted the file after I run git mv, and what steps I'd have gone through to produce this - I've just tried to reproduce, and got renamed:..; but 10 minutes ago I got a deleted:... on a file I'd git-mved about 10 minutes before that. It's confusing me greatly.

like image 395
simont Avatar asked Nov 02 '25 10:11

simont


1 Answers

It sounds like you renamed f1 to f2, but only committed the addition of f2 and not the removal of f1. This can happen if you use git mv f1 f2 but then type git commit f2, or it can happen if you type mv f1 f2 and then do something like git add .; git commit

like image 131
Lily Ballard Avatar answered Nov 04 '25 00:11

Lily Ballard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!