How can I split a single file using magit?

Let's say I made some unrelated changes to unrelated files in my git repository. I want to view and commit each of the files separately.

I run magit-status and get a list of modified files. But the only magit diff commands I can find ( d and d ) distinguish whole versions, not separate files.

I need the output of git diff <filename> , but in the magit diff buffer. How can I get magit to delimit only one file?

+45
git-diff emacs magit
Jul 22 '13 at 21:53
source share
3 answers

Magit allows you to "analyze and transfer each file separately" directly from the magit-status buffer without the need for any separate diff buffers.

You simply expand the files you are interested in (with a TAB that shows you the diff for the file at a point); then you can execute the bit that you want to commit (either the entire file, or individual pieces, or even the marked area) from s to the stage (or u to undefined). Repeat all changes associated with this commit, and as soon as everything is needed, press c to start the commit.

nb If you really want to view diff for a file in a separate buffer, you can use vc-diff bound to Cx v = in this file buffer. (nb this is the default functionality in Emacs, not part of Magit).

(edit: the answer is rewritten taking into account the aap comment, which now seems to be the opposite of what he had in mind at that time.)

+69
Jul 23 '13 at 0:16
source share

I recommend watching the video by the creator of magit. This is 20 minutes, and it shows you the workflow, as expected.

Also, a quick tip: you can use 1 2 3 to change the verbosity of the current title.

Another little tip: if you are not happy with the size of the pieces, you can create arbitrary regions - rightfully - marking areas and press s . This is magic. I did not know about this option for a while, I was actually dropping the console and doing git add -p old-fashioned way.

+21
Jul 23 '13 at 6:30
source share

There are certain advantages to not go against the grain when using tools, as evidenced by other answers.

On the other hand, sometimes you just want to tell your editor what to do and let people on the Internet answer your questions rather than say you want to do something else.

magit provides a menu interface for working with the current file through Mx magit-file-popup . The keys you need to click here are du. It may be too many keystrokes for you, if so, you can call magit-diff directly like this:

(magit-diff "master" nil (list buffer-file-name))

You may need to define your own function and key binding for this.

magit-diff has advantages over vc-diff , because if it allows you to go to the diff location.

+1
Nov 29 '16 at 4:14
source share



All Articles