Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use git mv from magit?

Tags:

git

emacs

magit

Is there a nice way to call git mv on a file from within magit? I know it's possible to run any git command with :, but this won't autocomplete filenames.

like image 748
Yossarian Avatar asked Jul 12 '13 08:07

Yossarian


People also ask

Does git mv do anything?

git mv moves the file, updating the index to record the replaced file path, as well as updating any affected git submodules. Unlike a manual move, it also detects case-only renames that would not otherwise be detected as a change by git.

How do I use Magit Emacs?

To use Magit, type M-x magit-status or C-x M-g j . You can also type C-x p m to open a Magit status buffer in your project root, if you use that functionality in Emacs. The status window is the most common entryway into Magit, but it is not the only one.

Is Magit part of Emacs?

As of September 2020, Magit is the most starred Emacs package on GitHub.


3 Answers

I'm not sure offhand if there's a direct way, but...

Given that a mv is the same thing as a rm plus an add, you can just rename the file normally (e.g. in dired), and then stage both of the consequent changes -- a deleted file and a new file.

Git should figure it out.

Edit:

M-x vc-rename-file ?

like image 62
phils Avatar answered Oct 18 '22 21:10

phils


For reference at least in current verion of magit there is magit-file-rename which can be invoked by R.

like image 33
Maciej Piechotka Avatar answered Oct 18 '22 21:10

Maciej Piechotka


I use dired for this. C-x d when the file is open, then press ! on the file to run git mv ? newpath command with the file as the ? argument.

like image 8
sp3ctum Avatar answered Oct 18 '22 22:10

sp3ctum