我能做点什么吗

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不添加。什么?


当前回答

您可以使用git别名,例如:

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

用在

git add-commit -m 'My commit message'

EDIT:返回到ticks('),否则在Linux上shell扩展将失败。在Windows上,应该使用双引号(")来代替(在评论中指出,没有验证)。

其他回答

我做一个壳层

#!/bin/sh

clear

git add -A 
git commit -a -m "'$*'"

例如保存为git.sh,然后调用:

sh git.sh your commit message

把你的命令组合起来:

git add -A && git commit -m "comment" 

有人说git commit -am可以做到。这将不起作用,因为它只能提交对跟踪文件的更改,但它不能添加新文件。源。

经过一番研究后,我发现没有这样的命令可以做到这一点,但是您可以在~/上编写一个脚本。bashrc,(~ /。Bash_profile或~/。zshrc取决于您的操作系统。

我将分享我使用的一个:

function gac {
  if [[ $# -eq 0 ]]
    then git add . && git commit
  else
    git add . && git commit -m "$*"
  fi
}

这样你所有的更改都会被添加并提交,你只需要输入gac,系统就会提示你写提交消息

或者你可以直接输入你的提交消息gac Hello world,你所有的更改都将被添加,你的提交消息将是Hello world,注意“”没有被使用

我有这个函数在我的。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的后期版本中,您可以像这样添加和提交

git commit -a -m "commit message"

另外你还有一个别名:

[alias]
    ac = commit -a -m

然后你可以这样使用它:

git ac "commit message"