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












6














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





























    6














    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



























      6












      6








      6


      3





      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

      16.1k24083




      16.1k24083










      asked Nov 27 at 7:29









      vmalloc

      1483




      1483






















          1 Answer
          1






          active

          oldest

          votes


















          10














          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






          • 1




            Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            Nov 30 at 7:47










          • It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
            – vmalloc
            Dec 19 at 9:39










          • magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
            – tarsius
            Dec 19 at 10:48










          • Doh! stupid me. You're right. Sorry for the hassle and thanks!
            – vmalloc
            9 hours 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',
          autoActivateHeartbeat: false,
          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









          10














          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






          • 1




            Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            Nov 30 at 7:47










          • It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
            – vmalloc
            Dec 19 at 9:39










          • magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
            – tarsius
            Dec 19 at 10:48










          • Doh! stupid me. You're right. Sorry for the hassle and thanks!
            – vmalloc
            9 hours ago
















          10














          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






          • 1




            Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            Nov 30 at 7:47










          • It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
            – vmalloc
            Dec 19 at 9:39










          • magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
            – tarsius
            Dec 19 at 10:48










          • Doh! stupid me. You're right. Sorry for the hassle and thanks!
            – vmalloc
            9 hours ago














          10












          10








          10






          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

          16.1k24083




          16.1k24083












          • 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






          • 1




            Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            Nov 30 at 7:47










          • It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
            – vmalloc
            Dec 19 at 9:39










          • magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
            – tarsius
            Dec 19 at 10:48










          • Doh! stupid me. You're right. Sorry for the hassle and thanks!
            – vmalloc
            9 hours 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
            Nov 27 at 13:13






          • 1




            Part 1 can be collapsed to git commit -a -m "the message"
            – Andrew Swann
            Nov 30 at 7:47










          • It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
            – vmalloc
            Dec 19 at 9:39










          • magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
            – tarsius
            Dec 19 at 10:48










          • Doh! stupid me. You're right. Sorry for the hassle and thanks!
            – vmalloc
            9 hours 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
          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




          1




          1




          Part 1 can be collapsed to git commit -a -m "the message"
          – Andrew Swann
          Nov 30 at 7:47




          Part 1 can be collapsed to git commit -a -m "the message"
          – Andrew Swann
          Nov 30 at 7:47












          It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
          – vmalloc
          Dec 19 at 9:39




          It seems like magit-call-git is no longer a thing? How do I do this with an up-to-date magit?
          – vmalloc
          Dec 19 at 9:39












          magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
          – tarsius
          Dec 19 at 10:48




          magit-call-git is still a thing. It is not autoloaded though, so I guess you tried to find its definition before actually loading magit.
          – tarsius
          Dec 19 at 10:48












          Doh! stupid me. You're right. Sorry for the hassle and thanks!
          – vmalloc
          9 hours ago




          Doh! stupid me. You're right. Sorry for the hassle and thanks!
          – vmalloc
          9 hours 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

          Probability when a professor distributes a quiz and homework assignment to a class of n students.

          Aardman Animations

          Are they similar matrix