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.
Asked
Active
Viewed 4,983 times
29

Yossarian
- 5,226
- 1
- 37
- 59
-
Just for information: what do you think `git mv` does? Do you realize that git does not track moves? git mv will just rename the file, remove the old name from the index and adds the new one. – Chronial Jul 12 '13 at 09:55
-
3Yep, it's just as everything else in magit is basically one/two keypress(es), I was hoping there was something for `mv`. – Yossarian Jul 12 '13 at 09:58
3 Answers
22
For reference at least in current verion of magit there is magit-file-rename
which can be invoked by R.

Maciej Piechotka
- 7,028
- 6
- 39
- 61
-
-
since magit buffer does not list tracked files, move the cursor to the last empty line and hit `R` to invoke magit-file-rename – frogcoder Mar 18 '21 at 01:01
20
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
?

phils
- 71,335
- 11
- 153
- 198
-
This works, but I was looking for something to do it automagically. `: mv /path/to/file1 /path/to/file2` (from a magit buffer) is even quicker, but it doesn't autocomplete. – Yossarian Jul 12 '13 at 10:00
-
1
-
How do I do force the `git mv`? I'm getting the error: "Please update files before moving them" – nnyby Jun 20 '14 at 16:06
-
nnyby: So I'm guessing there are unmerged changes to the file you're trying to move, so you should do as it says and merge in those changes first, otherwise I expect they'll be lost. If you're 100% certain you don't want the changes, the `-f` option might do the trick. (Failing that, you could always just copy the file, and manually restore it after merging.) – phils Jun 21 '14 at 01:22
8
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.

sp3ctum
- 429
- 6
- 9
-
This doesn't change the directory of the emacs buffer, which I often forget to my own confusion... – Jens Petersen May 24 '20 at 05:46