I am trying to write a function which stages all modified files and commits them.

Staging is easy - just run magit-stage-modified.

Committing is not - I couldn't find a way of creating a commit without invoking commit-message-buffer.

Ideally I'd like to have an interactive function looking like this:

(defun just-stage-and-commit (commit-msg)
  ;; ...

Any hints? Thanks in advance!

  • 2
    You could always resort to calling (magit-git-command ARGS DIRECTORY) with the specific git command you want.
    – wvxvw
    Feb 8 '16 at 10:39

If you provide the -m option to magit-commit it will use what your provided and not open the message buffer.

(defun my-magit-stage-all-and-commit(message)
  (interactive "sCommit Message: ")
  (magit-commit (list "-m" message)))
  • 1
    I think that should be (magit-commit "-m" message)
    – npostavs
    Feb 8 '16 at 19:29
  • 1
    magit-commit takes 1 arg: (magit-commit &optional ARGS), at least in the version I have. Feb 8 '16 at 19:44
  • 3
    Ah, right, I got confused, should have been (magit-commit (list "-m" message))
    – npostavs
    Feb 8 '16 at 21:54
  • Both will work, but that does look cleaner, I'll use that. Feb 11 '16 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.