我能做点什么吗

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 commit -a -m "commit message"

另外你还有一个别名:

[alias]
    ac = commit -a -m

然后你可以这样使用它:

git ac "commit message"

其他回答

我做一个壳层

#!/bin/sh

clear

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

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

sh git.sh your commit message

如果你输入:

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

一次,你只需要打字

git a

每一次:

git a 'your comment'
git commit -am "message"

是告诉git删除已删除文件的一种简单方法,但我通常不推荐这种一刀切的工作流程。在最佳实践中,Git提交应该是相当原子的,并且只影响少数文件。

git add .
git commit -m "message"

是添加所有新建或修改过的文件的简单方法。此外,适用于所有限定条件。上述命令不会删除未使用git rm命令删除的文件。

git add app
git commit -m "message"

是一种将所有文件从单个目录添加到索引的简单方法,在本例中是app目录。

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

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

用在

git add-commit -m 'My commit message'

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

以下是Lenar Hoyt的gac提案的增强版:

function gac() {

  if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
    # displays help with
    # gac | gac -h | gac --help
    echo "------"
    echo "Cannot commit without comments. Semantic reminder:"
    echo "chore:        c" 
    echo "docs:         d" 
    echo "feat:         f" 
    echo "refactor:     r" 
    echo "style:        s"
    echo "test:         t" 
    echo "fix:          x"
    echo "------"
    return 1
  fi  

  SHORTCUT=$1
  shift ;
  COMMENT=$@

  # Chore
  if [ "$SHORTCUT" = "c" ]; then
    SHORTCUT="chore:"

  # Write or edit existing documentation
  elif [ "$SHORTCUT" = "d" ]; then
    SHORTCUT="docs:"

  # Add new feature
  elif [ "$SHORTCUT" = "f" ]; then
    SHORTCUT="feat:"

  # Refator your code base
  elif [ "$SHORTCUT" = "r" ]; then
    SHORTCUT="refactor:"

  # Styling actions
  elif [ "$SHORTCUT" = "s" ]; then 
    SHORTCUT="style:"

  # Test your code
  elif [ "$SHORTCUT" = "t" ]; then 
    SHORTCUT="test:"

  # Working on a feature
  elif [ "$SHORTCUT" = "x" ]; then 
    SHORTCUT="fix:"
  fi
  
  # res with or without semantic
  git add -A && git commit -m "$SHORTCUT $COMMENT"
  return 1
}

它将允许您访问以下命令:

gac
# print available semantics

gac c <your message>
# git add -A && git commit -m "chore: <your message>"

gac d <your message>
# git add -A && git commit -m "docs: <your message>"

gac f <your message>
# git add -A && git commit -m "feat: <your message>"

gac r <your message>
# git add -A && git commit -m "refactor: <your message>"

gac s <your message>
# git add -A && git commit -m "style: <your message>"

gac t <your message>
# git add -A && git commit -m "test: <your message>"

gac x <your message>
# git add -A && git commit -m "fix: <your message>"

gac <your message>
# git add -A && git commit -m "<your message>"