I implemented the following to git commit after a file is saved. It works, I think, but the commit message, rather than being empty, is the literal value ''. This is the case whether or not I have any text in the quotes after the -m.

I expect my quoting is wrong - can someone confirm or deny please?

  (defun my-after-save-actions ()
    "Used in `after-save-hook'."
    (if (string-match-p (regexp-quote "Journal.org") (buffer-file-name))
        (shell-command "git add Journal.org && git commit --allow-empty-message -m ''")

  (add-hook 'after-save-hook 'my-after-save-actions)
  • The function seems to be missing a couple of parens. I tried M-: (shell-command "git add Journal.org && git commit --allow-empty-message -m ''") RET but I cannot reproduce the problem.
    – NickD
    Commented Sep 28, 2023 at 18:59
  • 1
    Possibly a Windows thing :( I don't get the same (undesired) behaviour in WSL. Commented Sep 28, 2023 at 19:44
  • Correction: just one paren is missing (and I added it in the edit).
    – NickD
    Commented Sep 28, 2023 at 20:37

1 Answer 1


Yes, appears to be a Windows thing. Simply replacing the -m '' with -m \"\" does the job. Could have sworn I tried that, but I guess not.

  • Which shell are you using?
    – phils
    Commented Sep 29, 2023 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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