Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between running "git mv" versus just "mv"

Tags:

git

What is actual difference in results when it comes to source control systems, between running a command like:

git mv <src> <dest>  // see: https://git-scm.com/docs/git-mv

versus a "lower" level command like

mv <src> <dest>

is there any difference in the result from a version/source control system's perspective? Or anything/anyone's perspective?

The same goes for other git commands like git rm. I just want to know what difference it makes between running the git functions versus bash functions, or whatever.

like image 583
Alexander Mills Avatar asked Oct 19 '16 07:10

Alexander Mills


2 Answers

git mv stages the move, so you can just git commit afterwards. If you move the file manually, you need to manually stage the move before committing.

Other than that, there is no difference there is just the minor difference Leon's answer covers. The documentation for git mv says:

Move or rename a file, directory or symlink.

...

The index is updated after successful completion, but the change must still be committed.

like image 51
1615903 Avatar answered Oct 04 '22 20:10

1615903


Just an extra piece of information, complementing the other answers (this applies solely to giv mv):

If file <dest> exists (no matter tracked or not) then

mv <src> <dest>

will silently overwrite it, whereas

git mv <src> <dest>

refuses to overwrite it, with the following error message:

fatal: destination exists, source=<src>, destination=<dest>
like image 32
Leon Avatar answered Oct 04 '22 22:10

Leon