代码之家  ›  专栏  ›  技术社区  ›  Chetan

在一个命令中添加和提交Git

git
  •  312
  • Chetan  · 技术社区  · 14 年前

    我能做什么吗

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

    在一个命令中?

    我似乎经常做这两个命令,如果Git有这样的选择 git commit -Am "commit message" 它会使生活更加方便。

    git commit -a 修饰符,但它的作用与 git add -A 在提交之前。 Git加-A 添加新创建的文件,但 git commit -am 没有。什么?

    21 回复  |  直到 5 年前
        1
  •  348
  •   Martin Carpella    7 年前

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

    git add-commit -m 'My commit message'
    

        2
  •  214
  •   wonea Ilya Smagin    7 年前
    git commit -a -m "message"
    

    git add .
    git commit -m "message"
    

    git rm

    git add app
    git commit -m "message"
    

        3
  •  47
  •   Ales    13 年前

    git add . && git commit -am "comment"
    

        4
  •  18
  •   Yarin    10 年前

    git add -A && git commit -m "comment" 
    
        5
  •  17
  •   danilo    7 年前

    Ales's courtsimas's

    git commit -am "comment"

    git add . ; git commit -am "message"

        6
  •  13
  •   sirwinny    8 年前

    git commit -a -m "commit message"
    

    [alias]
        ac = commit -a -m
    

    git ac "commit message"
    
        7
  •  11
  •   Blair Anderson    7 年前

    git commit -am "commit all the things"
    
        8
  •  8
  •   Community kfsone    7 年前

    .bashrc

    • refer SO thread
    • alias gacp='echo "enter commit message : " && read MSG && git add . && git commit -m "$MSG" && git push'
      

    • gacp
        9
  •  5
  •   Josh Olson    6 年前

    git commit -m "message" .     
    

        10
  •  4
  •   ademar111190    13 年前

    #!/bin/sh
    
    clear
    
    git add -A 
    git commit -a -m "'$*'"
    

    sh git.sh your commit message
    
        11
  •  4
  •   Positive Navid    8 年前

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

    git a
    

    git a 'your comment'
    
        12
  •  4
  •   Lenar Hoyt    7 年前

    .bash_profile .profile .zprofile

    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"
    }
    
        13
  •  2
  •   Druta Ruslan    6 年前

    -a

    git commit -h
    
    ...
    Commit contents options
        -a, -all    commit all changed files
    ...
    
    git commit -a # It will add all files and also will open your default text editor.
    
        14
  •  1
  •   avjaarsveld    8 年前

    # Add All and Commit
      aac = !echo "Enter commit message:" && read MSG && echo "" && echo "Status before chagnes:" && echo "======================" && git status && echo "" && echo "Adding all..." && echo "=============" && git add . && echo "" && echo "Committing..." && echo "=============" && git commit -m \"$MSG\" && echo "" && echo "New status:" && echo "===========" && git status
    
    # Add All and Commit with bumpted Version number
      aacv = !echo "Status before chagnes:" && echo "======================" && git status && echo "" && echo "Adding all..." && echo "=============" && git add . && echo "" && echo "Committing..." && echo "=============" && git commit -m \"Bumped to version $(head -n 1 VERSION)\" && echo "" && echo "New status:" && echo "===========" && git status
    

    echo "Enter commit message:" && read MSG

    if else .zshrc

        15
  •  1
  •   Gus    8 年前

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

    git ac
    

        16
  •  0
  •   Alejandro Silva    9 年前

    git config --global alias.cam '!git commit -a -m '

    git add -A && git commit -m "this is a great commit"

    git cam "this is a great commit"

        17
  •  0
  •   Gaurav Rathi    7 年前

        18
  •  0
  •   Filnor    6 年前

    git config --get-regexp alias
    

    https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases

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

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

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

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

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

    git acm 'My commit'
    
        19
  •  0
  •   Bruno Negrão Zica    5 年前

    #!/bin/bash
    
    function usage {
        echo "Usage: $(basename $0) <filename> <commit_message>"    
    }
    
    function die {
        declare MSG="$@"
        echo -e "$0: Error: $MSG">&2
        exit 1
    }
    
    (( "$#" == 2 )) || die "Wrong arguments.\n\n$(usage)"
    
    FILE=$1
    COMMIT_MESSAGE=$2
    
    [ -f $FILE ] || die "File $FILE does not exist"
    
    echo -n adding $FILE to git...
    git add $FILE || die "git add $FILE has failed."
    echo done
    
    echo "commiting $file to git..."
    git commit -m "$COMMIT_MESSAGE" || die "git commit has failed."
    
    exit 0
    

    gitfile.sh /path/to/file "MY COMMIT MESSAGE"
    
        20
  •  -1
  •   Kosmos Nagios    7 年前
    1. git add . && git commit -am
    2. history
    3. 543
    4. !543 "your comment here"
        21
  •  -3
  •   Sathish Ravula    9 年前

    gacm "your comment"