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











up vote
5
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
    5
    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
      5
      down vote

      favorite
      2









      up vote
      5
      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 Nov 27 at 11:00









      tarsius

      15.9k23981




      15.9k23981










      asked Nov 27 at 7:29









      vmalloc

      1433




      1433






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          8
          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
            Nov 27 at 13:13










          • Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            yesterday











          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
          8
          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
            Nov 27 at 13:13










          • Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            yesterday















          up vote
          8
          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
            Nov 27 at 13:13










          • Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            yesterday













          up vote
          8
          down vote



          accepted







          up vote
          8
          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 Nov 27 at 11:00

























          answered Nov 27 at 10:14









          tarsius

          15.9k23981




          15.9k23981












          • 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
            Nov 27 at 13:13










          • Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            yesterday


















          • 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
            Nov 27 at 13:13










          • Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            yesterday
















          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
          Nov 27 at 13:13




          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
          Nov 27 at 13:13












          Part 1 can be collapsed to git commit -a -m "the message"
          – Andrew Swann
          yesterday




          Part 1 can be collapsed to git commit -a -m "the message"
          – Andrew Swann
          yesterday


















          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

          數位音樂下載

          When can things happen in Etherscan, such as the picture below?

          格利澤436b