我能做点什么吗

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

一个命令?

我似乎经常使用这两个命令,如果Git有一个像Git commit -Am“commit message”这样的选项,它会让生活变得更方便。

git commit有-a修饰符,但它不完全等同于在提交前执行git add -a。git add -A添加新创建的文件,但git commit -am不添加。什么?


当前回答

在bash中创建别名: alias gac="git add -A && git commit -m" (我选择称这个快捷方式为“gac”,但你不必这么做) 使用它:gac '你的提交信息在这里'

其他回答

你可以使用-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.

我有这个函数在我的。bash_profile或。profile或。zprofile或任何登录shell中的来源:

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"
}

最简单的方法是:

git commit -am "Your commit message"

我不明白我们为什么要搞得这么复杂。

只使用:

git commit -m "message" .     

注意结尾的"."…也可以是文件/目录的路径

这回答了标题中的问题。不是描述里的问题,但我想在座的各位可能会觉得这个问题很有用。

下面的bash脚本在一个命令中添加并提交文件。它不添加所有的文件,它只是添加您在命令行上指定的文件。如果命令行上没有指定任何文件,可以很容易地将其修改为添加所有文件。然而,这对我来说似乎有点危险,所以我没有这么做。

#!/bin/bash

if [[ $# -lt 2 ]]
then
    echo "Usage:  $(basename $0) FILENAME+ \"COMMIT_MESSAGE\""
    echo 
    echo 'Shorthand for "git add FILENAME_0 FILENAME_1 .. FILENAME_n && git commit -m "COMMIT MESSAGE".'
    echo 'You must specify at least one filename, and supply one single commit message.'
    echo 
else    
    git add ${*: 1: $#-1} && git commit -m "${*: -1}"
fi

将它保存在一个名为gac的文件中,然后像这样使用它

gac file_a file_b file_c "adding three files because.. reasons"

在这个帖子中引用@LuisEnMarroquin的作品。