Git add and commit in one command

后端 未结 27 2253
旧巷少年郎
旧巷少年郎 2020-11-28 00:28

Is there any way I can do

git add -A
git commit -m \"commit message\"

in one command?

I seem to be doing those two commands a lot,

相关标签:
27条回答
  • 2020-11-28 00:50

    This Result - Try this: Simple script one command for git add, git commit and git push

    Open your CMD on Windows and paste this answer

    git commit -m "your message" . && git push origin master

    This example my picture screenshot : https://i.stack.imgur.com/2IZDe.jpg

    0 讨论(0)
  • 2020-11-28 00:51

    I have this function in my .bash_profile or .profile or .zprofile or whatever gets sourced in login shells:

    function gac () {
      # Usage: gac [files] [message]
      # gac (git add commit) stages files specified by the first argument
      # and commits the changes with a message specified by the second argument.
      # Using quotes one can add multiple files at once: gac "file1 file2" "Message".
      git add $1 && git commit -m "$2"
    }
    
    0 讨论(0)
  • 2020-11-28 00:52

    Check first what aliases you have...

    git config --get-regexp alias
    

    If it's not there you can create your own (reference: https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases)

    // git add

    git config --global alias.a '!git add -A'
    

    // git commit

    git config --global alias.c '!git commit'
    

    // git commit -m

    git config --global alias.cm '!git commit -m'
    

    // git add commit

    git config --global alias.ac '!git add -A && git commit'
    

    // git add commit -m

    git config --global alias.acm '!git add -A && git commit -m'
    

    For instance, if you use the last one...

    git acm 'My commit'
    
    0 讨论(0)
  • 2020-11-28 00:53

    pretty sure you can use:

    git commit -am "commit all the things"
    
    0 讨论(0)
  • 2020-11-28 00:54

    You can use git aliases, e.g.

    git config --global alias.add-commit '!git add -A && git commit'
    

    and use it with

    git add-commit -m 'My commit message'
    

    EDIT: Reverted back to ticks ('), as otherwise it will fail for shell expansion on Linux. On Windows, one should use double-quotes (") instead (pointed out in the comments, did not verify).

    0 讨论(0)
  • 2020-11-28 00:54

    you can use git commit -am "[comment]" // best solution or git add . && git commit -m "[comment]"

    0 讨论(0)
提交回复
热议问题