Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the purpose of git-mv?

Tags:

git

git-mv

From what I understand, Git doesn't really need to track file rename/move/copy operations, so what's the real purpose of git mv? The man page isn't specially descriptive...

Is it obsolete? Is it an internal command, not meant to be used by regular users?

like image 202
Mauricio Scheffer Avatar asked Jul 07 '09 19:07

Mauricio Scheffer


People also ask

What is the use of git mv?

We use the git mv command in git to rename and move files. We only use the command for convenience. It does not rename or move the actual file, but rather deletes the existing file and creates a new file with a new name or in another folder.

Is git mv necessary?

In Git's case, it will try to auto-detect renames or moves on git add or git commit; if a file is deleted and a new file is created, and those files have a majority of lines in common, Git will automatically detect that the file was moved and git mv isn't necessary.

How do I rename a directory in git without losing history?

emiller/git-mv-with-history. git utility to move/rename file or folder and retain history with it. # git-mv-with-history -- move/rename file or folder, with history. # Git has a rename command git mv, but that is just for convenience.


1 Answers

git mv oldname newname 

is just shorthand for:

mv oldname newname git add newname git rm oldname 

i.e. it updates the index for both old and new paths automatically.

like image 155
CB Bailey Avatar answered Oct 18 '22 01:10

CB Bailey