我能做点什么吗

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


当前回答

我希望这能帮助到一些人,请随意编辑或改进。我不知道最快的方法是什么,但这确实简化了我的代码提交过程使用“ohmyzsh”Git。

https://ohmyz.sh/

Git添加。缩写为ga。 Git commit -m "message"缩写为gc -m "message" Git push被缩短为gp Git取回被缩短为gf Git拉源master缩短为GGL master Git push origin master被缩短为GGP master Git checkout -b缩写为GCB Git merge缩写为gm Git remote缩写为gr Git状态缩短为GST

其他回答

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

下面的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的作品。

只适应Ales的回答和courtsimas的评论linux bash:

要保持在一行中使用:

Git commit -am "comment"

这一行将添加并提交所有更改到存储库。

只要确保没有git还未拾取的新文件就可以了。否则你需要使用:

Git添加。; Git commit -am "message"

我有这个函数在我的。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"
}

对于人群中的银背,他们习惯了Subversion……我通常在我的项目的根目录中添加如下内容(在windows中作为一个bat文件,例如git-commit.bat)。然后当我想添加、提交和推送时,我只需输入git-commit“添加了一些新东西”这样的东西,它就会全部到远程回购。

此外,这样项目中的任何人都可以使用相同的,而不必在本地更改任何内容。

我通常也运行git配置凭证。helper存储一次,所以我不需要给uid/pwd时,这是运行。

::
:: add, commit, and push to git
::

@echo off
echo.
echo.
echo 
echo Doing commit...
git add -A && git commit -m %1
echo.
echo.
echo Doing push...
git push
echo.
echo.
echo Done.
echo.

我做一个壳层

#!/bin/sh

clear

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

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

sh git.sh your commit message