Practical use case of 'git rm' and 'git mv' with git?
Asked Answered
M

3

8

I know that git provides the 'git rm' and 'git mv' to remove/move files or directories. But, I can't see the practical use case for this.

Normally, I just mv or rm the files or whatever in the command line, and after I'm done with all the necessary actions, I can just run 'git add -u' and 'git add .', as I asked and got answers in here.

Am I missing something? Are there any cases that only 'git rm' and 'git mv' capable of?

Marmot answered 3/9, 2010 at 20:31 Comment(0)
M
10

git mv and git rm are about updating the index directly. While directly moving or deleting files in the working tree won't immediately affect the index.

The GitFaq does present git mv as:

just a convenience. The effect is indistinguishable from removing the file and adding another with different name and the same content.

Maulmain answered 3/9, 2010 at 20:47 Comment(0)
B
4

git rm and git mv allows you to be more specific/granular about what you're doing. If you've deleted two directories and want to split up those deletions between two commits, you can use git rm to remove only one directory from the staging area, rather than getting them both via git -u

Bridgehead answered 3/9, 2010 at 21:15 Comment(0)
C
1

you could do it the way you said, but it sounds like it would be simpler to use git rm and git mv as it's a one-step process.

Chlodwig answered 3/9, 2010 at 20:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.