Wandering Thoughts archives

2015-12-25

I like Magit, the GNU Emacs package for Git

As part of slowly improving my GNU Emacs environment, I recently decided to experiment with magit, a very well regarded Emacs package for working with Git. I'm not attempting to adopt it as my primary interface to Git (I'm not a 'do everything from inside Emacs' person); instead, I have relatively specific situations where I was hoping magit would be the best way to work with Git. Although I haven't used it extensively yet, I can definitely say that Magit has been great in the areas where I was hoping that it would be.

For me, the big Magit feature and selling point is selectively adding things to the Git index (that is, staging them before committing them). Ordinary command line Git has 'git add -p', but this is a relatively awkward interface that I have had blow up in my face before. Magit offers a very powerful interface for selectively staging changes; you can easily stage not just individual chunks of the diff but even individual lines and collections of them. This is a very powerful way of straightening out a tangle of changes into logical changesets, even if they don't come out in separate chunks.

Part of why Magit makes this relatively easy is that it gives you a good live display of the staged and unstaged diffs as you are working away. This means you get immediate feedback if something looks wrong (or incomplete), and you can also reverse a decision right away. With 'git add -p' I found that I didn't really get this, since it's pretty much a linear process through all the chunks of diffs. In fact being non-linear is another advantage of Magit here; you can see the full set of diffs and skip around it to spot bits that you want to commit first.

Magit also has a relatively nice interface for just making commits. You get an Emacs buffer to edit the commit message (with standard general Emacs features like spell checking) and it shows you the staged diff that will be committed at the same time, which is handy. I can pretty much get all of this at the command line with multiple windows, but if I'm already in Emacs for editing files I often might as well commit from Emacs as well.

I have much less exposure to other Magit features, at least some of which I'm not terribly interested in (at least right now, I may change my mind later). How you invoke Magit commands initially struck me as a bit weird and confusing, but I'm getting used to it with time. People who regularly use Magit will likely find it completely natural.

So, in summary: Magit rocks for selectively staging changes, so much so that I think it's worth turning to GNU Emacs with Magit for this if you need it, even if you regularly edit in something else. If you regularly use GNU Emacs anyways I think the other parts of Magit are useful enough to learn at least the basics of looking at diffs and making straightforward commits.

(Although I spend a lot of time in vi, GNU Emacs remains my favorite editor for working on code in most languages for reasons beyond the scope of this entry.)

programming/MagitPraise written at 01:38:11; Add Comment


Page tools: See As Normal.
Search:
Login: Password:
Atom Syndication: Recent Pages, Recent Comments.

This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.