How to perform an automatic commit with predefined message using Magit?











up vote
4
down vote

favorite
2












I have a repository of org files which I mostly use for note taking and tracking, and I track it using git. I want to add a shortcut that would quickly commit all current content of the repository (both changed, new and deleted files) as a new commit with a predefined commit message (say "update"). How can I achieve this programmatically with magit?



Thanks in advance!










share|improve this question




























    up vote
    4
    down vote

    favorite
    2












    I have a repository of org files which I mostly use for note taking and tracking, and I track it using git. I want to add a shortcut that would quickly commit all current content of the repository (both changed, new and deleted files) as a new commit with a predefined commit message (say "update"). How can I achieve this programmatically with magit?



    Thanks in advance!










    share|improve this question


























      up vote
      4
      down vote

      favorite
      2









      up vote
      4
      down vote

      favorite
      2






      2





      I have a repository of org files which I mostly use for note taking and tracking, and I track it using git. I want to add a shortcut that would quickly commit all current content of the repository (both changed, new and deleted files) as a new commit with a predefined commit message (say "update"). How can I achieve this programmatically with magit?



      Thanks in advance!










      share|improve this question















      I have a repository of org files which I mostly use for note taking and tracking, and I track it using git. I want to add a shortcut that would quickly commit all current content of the repository (both changed, new and deleted files) as a new commit with a predefined commit message (say "update"). How can I achieve this programmatically with magit?



      Thanks in advance!







      magit






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      tarsius

      15.8k23981




      15.8k23981










      asked 2 days ago









      vmalloc

      1383




      1383






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          There are two parts to this task.





          1. Figuring out how to do this on the command line.



            $ git add .
            $ git commit -m "the message"



          2. Figuring out what Magit functions can be used to call Git commands.



            You can either use commands or you can use low-level functions. I would recommend doing the latter, but looking at the definitions of the former might help locating the latter. The manual section named Calling Git would also come in handy.



            Looking at that page you will learn that you should probably use magit-call-git and/or magit-run-git. The difference is that the latter also refreshes the current Magit buffer and the status buffer and doing that twice would be wasteful. So either use each function once or the latter twice and call magit-refresh explicitly.



            (magit-call-git "add" ".")
            (magit-call-git "commit" "-m" "the message")
            (magit-refresh)



          Now wrap that in a command and bind a key to it. You might even want to add the command to the commit popup by Customizing [this] Existing Popup.






          share|improve this answer























          • Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
            – Nathaniel Pisarski
            2 days ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "583"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f46244%2fhow-to-perform-an-automatic-commit-with-predefined-message-using-magit%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote



          accepted










          There are two parts to this task.





          1. Figuring out how to do this on the command line.



            $ git add .
            $ git commit -m "the message"



          2. Figuring out what Magit functions can be used to call Git commands.



            You can either use commands or you can use low-level functions. I would recommend doing the latter, but looking at the definitions of the former might help locating the latter. The manual section named Calling Git would also come in handy.



            Looking at that page you will learn that you should probably use magit-call-git and/or magit-run-git. The difference is that the latter also refreshes the current Magit buffer and the status buffer and doing that twice would be wasteful. So either use each function once or the latter twice and call magit-refresh explicitly.



            (magit-call-git "add" ".")
            (magit-call-git "commit" "-m" "the message")
            (magit-refresh)



          Now wrap that in a command and bind a key to it. You might even want to add the command to the commit popup by Customizing [this] Existing Popup.






          share|improve this answer























          • Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
            – Nathaniel Pisarski
            2 days ago















          up vote
          6
          down vote



          accepted










          There are two parts to this task.





          1. Figuring out how to do this on the command line.



            $ git add .
            $ git commit -m "the message"



          2. Figuring out what Magit functions can be used to call Git commands.



            You can either use commands or you can use low-level functions. I would recommend doing the latter, but looking at the definitions of the former might help locating the latter. The manual section named Calling Git would also come in handy.



            Looking at that page you will learn that you should probably use magit-call-git and/or magit-run-git. The difference is that the latter also refreshes the current Magit buffer and the status buffer and doing that twice would be wasteful. So either use each function once or the latter twice and call magit-refresh explicitly.



            (magit-call-git "add" ".")
            (magit-call-git "commit" "-m" "the message")
            (magit-refresh)



          Now wrap that in a command and bind a key to it. You might even want to add the command to the commit popup by Customizing [this] Existing Popup.






          share|improve this answer























          • Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
            – Nathaniel Pisarski
            2 days ago













          up vote
          6
          down vote



          accepted







          up vote
          6
          down vote



          accepted






          There are two parts to this task.





          1. Figuring out how to do this on the command line.



            $ git add .
            $ git commit -m "the message"



          2. Figuring out what Magit functions can be used to call Git commands.



            You can either use commands or you can use low-level functions. I would recommend doing the latter, but looking at the definitions of the former might help locating the latter. The manual section named Calling Git would also come in handy.



            Looking at that page you will learn that you should probably use magit-call-git and/or magit-run-git. The difference is that the latter also refreshes the current Magit buffer and the status buffer and doing that twice would be wasteful. So either use each function once or the latter twice and call magit-refresh explicitly.



            (magit-call-git "add" ".")
            (magit-call-git "commit" "-m" "the message")
            (magit-refresh)



          Now wrap that in a command and bind a key to it. You might even want to add the command to the commit popup by Customizing [this] Existing Popup.






          share|improve this answer














          There are two parts to this task.





          1. Figuring out how to do this on the command line.



            $ git add .
            $ git commit -m "the message"



          2. Figuring out what Magit functions can be used to call Git commands.



            You can either use commands or you can use low-level functions. I would recommend doing the latter, but looking at the definitions of the former might help locating the latter. The manual section named Calling Git would also come in handy.



            Looking at that page you will learn that you should probably use magit-call-git and/or magit-run-git. The difference is that the latter also refreshes the current Magit buffer and the status buffer and doing that twice would be wasteful. So either use each function once or the latter twice and call magit-refresh explicitly.



            (magit-call-git "add" ".")
            (magit-call-git "commit" "-m" "the message")
            (magit-refresh)



          Now wrap that in a command and bind a key to it. You might even want to add the command to the commit popup by Customizing [this] Existing Popup.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered 2 days ago









          tarsius

          15.8k23981




          15.8k23981












          • Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
            – Nathaniel Pisarski
            2 days ago


















          • Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
            – Nathaniel Pisarski
            2 days ago
















          Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
          – Nathaniel Pisarski
          2 days ago




          Since I had trouble with this at first, if anyone wants to make a keybinding which executes multiple commands, you could do some eval magic, or use progn.
          – Nathaniel Pisarski
          2 days ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Emacs Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2femacs.stackexchange.com%2fquestions%2f46244%2fhow-to-perform-an-automatic-commit-with-predefined-message-using-magit%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy