magit.org 6.1 KB

Introduction to Magit

Basic commands

Many commands in magit pop up a small buffer prompting you to specify options. To see the commits for a specific file, in the git status buffer type "l -f ". Then you will see all of the commits for 1 file! cool! You typically start a magit section by running magit-status. You can stage un-staged with "s". You can commit those changes with "cc". You can push those changes with "Pp".

magit commands in the status buffer

Un-staging commits can be done via "u".

  • $ will add another buffer that shows you the commands magit is commiting
  • s on a modified file will stage it
  • S will stage all modified files
  • i will add the current file to the project’s git ignore
  • u will unstage the current modified file
  • c c will commit your staged changes. Type in a message in the buffer that appears, and then hit C-c C-c to close the buffer
  • P P will push your changes
  • F F will pull your changes
  • y will take you to the branch manager

history commands

Branch Manager commands

  • l r l will allow you to see the commits that make two branches differ. This happens when branch "master" is behind branch "new feature". You can see the differences between the two branches and cherrypick them.
  • a will apple the current commit to your current branch. This allows me to cherry pick changes from one "bug fix" branch to the
  • "master" branch.
  • A does the same as above, but it tries to automatically commit the changes if there are no merge conflicts.
  • v will revert the commit. It will apply the changes made by a commit in reverse. But you still need to commit the changes.
  • ~.~ toggle mark on a commit
  • C-c u unmark marked commits
  • = show the differ between the marked commit and the commit under point
  • k will delete the branch under point
  • C-u k will force delete a branch under point
  • c will create a new branch
  • r renames the branch

magit bisect

Using magit to apply patches from upstream to a local repo.

  • T on a local branch changes which remote branch it tracks
  • Wow! Super easy way to narrow down to commit that caused an issue! http://oremacs.com/2014/12/31/keymap-arms-race/ https://emacs.stackexchange.com/questions/36885/how-do-i-apply-a-patch-from-gnus-to-a-git-repo

First find the patch via issues.guix.gnu.org or debbugs.

guix install emacs-debbugs

M-x debbugs-gnu-search BugNumber RET ([2022-07-07 Thu] I cannot do this on doom emacs currently. Do a emacs -q and it'll work.)

Find the email via debbugs, and type in O m to save the file.

Then open up M-x magit-status RET w m to apply the patch.

magit may give you an odd error. But you can always check the log. Sometimes it applies the patch, and still gives you an error.

:ircChats:

gnucode │ is there an easy way to apply a patch from debbugs-gnu to my local guix repository? unmatched-paren │ gnucode: download the mbox and `git am` away :) gnucode │ unmatched-paren that seems very tedious... unmatched-paren │ curl might be able to make it easier gnucode │ It would be nice if I could apply the patch from emacs and debbugs...just my 2 cents. morganw │ I think there is an Emacs package which can apply git patches that are in a mail message. unmatched-paren │ I use aerc which allows me to download and apply the mbox automatically, not sure whether $EMACS_MAIL_CLIENT can do that unmatched-paren │ aerc command is :pipe -mb git am -3 unmatched-paren │ "pipe the mbox into git am three-way" gnucode │ unmatched-paren are you using mbox to read the guix email achives? unmatched-paren │ gnucode: what do you mean? unmatched-paren │ i think aerc uses maildir by default gnucode │ ok. Maybe I should give aerc a try. I keep wanting to use emacs for most of my email and everything needs. But I have a really hard time figuring out how to use it. gnucode │ I used to be able to send email via emacs...now I can't. morganw │ gnucode: I think this is one some people use: https://git.kyleam.com/piem unmatched-paren │ aerc uses vi commands, fyi gnucode │ I am using evil-mode unmatched-paren │ ah unmatched-paren │ gnucode: I'm afraid my patch adding aerc hasn't been merged yet though unmatched-paren │ because of the general lack of vi users around here :) morganw │ It believe that if you use Gnus there is also a built in command to send the message buffer to a pipe and so something with it. morganw │ *do something morganw │ Or possibly it was built into message mode, I think I tried it once but I don't remember the exact process. unmatched-paren │ maybe there's a way to pipe the mbox too gnucode │ I just found this: https://emacs.stackexchange.com/questions/36885/how-do-i-apply-a-patch-from-gnus-to-a-git-repo gnucode │ seems promising unmatched-paren │ nice! ulfvonbelow │ M-> C- M-< M-| ulfvonbelow │ that works with any buffer btw rekado_ │ gnucode: I use mu4e (which uses gnus message mode to display emails) and wired up the mu4e-action-git-apply-mbox action. gnucode │ rekado_: do you ever use debbugs? rekado_ │ I dog-food mumi / issues.guix.gnu.org gnucode │ rekado_: hahah. :END:

magit blame

Visit a magit buffer and run magit-blame. Magit will divide the buffer into regions, and list which region belongs to which git author and in what commit. It awesome!

M-w saves the hash of the current region to the kill ring.

"n" and "p" move to the next and previous hunks.

split up a commit with magit

https://www.youtube.com/watch?v=mtliRYQd0j4

Put point on a commit you want to split open:

Rebase -> m modify a commmit

magit-reset (x) RET head~ RET

This puts head at the position before the commit you want to modify. And you are free to split the commit.

rebase -> c continue for complete the action