我能做点什么吗

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 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上,应该使用双引号(")来代替(在评论中指出,没有验证)。


要保持在一行中使用:

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

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


我做一个壳层

#!/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" 

在我的windows机器上,我设置了这个.bashrc别名,使整个过程更简单。

创建/定位.bashrc - refer SO线程 将以下行添加到文件中 alias gacp='echo "enter commit message: " && read MSG && git add . "&& git commit -m "$MSG" && git push' git添加了commit和push。以任何方式调整它,假设你不想要push命令删除那部分 重新加载.bashrc / close并重新打开shell 现在您可以使用gacp命令完成整个过程。


我使用这个git别名:

Git配置——全局别名。凸轮”!Git提交-a -m '

所以,不是打电话

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

我只会:

Git CAM“这是一个伟大的承诺”


我使用以下方法(这两种方法都在进行中,所以我会尽量记得更新):

# 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

呼应“Enter commit message:”&&读取MSG部分,灵感来自Sojan V Jose

我想在那里得到一个if else语句,这样我就可以让aacv问我,如果我想部署时,如果我键入'y',为我这样做,但我想我应该把它放在我的.zshrc文件


如果你输入:

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

一次,你只需要打字

git a

每一次:

git a 'your comment'

在git的后期版本中,您可以像这样添加和提交

git commit -a -m "commit message"

另外你还有一个别名:

[alias]
    ac = commit -a -m

然后你可以这样使用它:

git ac "commit message"

我使用以下别名添加所有并提交:

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

然后,输入:

git ac

我得到了一个vim窗口来为我的提交消息获得更多的编辑工具。


你可以使用

git commit -am "[comment]" # best solution 

or

git add . && git commit -m "[comment]"

很确定你可以用:

git commit -am "commit all the things"

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

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

要保持在一行中使用:

Git commit -am "comment"

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

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

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


只使用:

git commit -m "message" .     

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


首先检查你有哪些别名……

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提交

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

// git提交-m

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

// git添加提交

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

// git add commit -m

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

例如,如果你用最后一个…

git acm 'My commit'

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

如果有人想为单个文件“添加并提交”,这是我的情况,我创建了下面的脚本来做到这一点:

#!/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中。然后我可以在一个命令中运行git add并提交单个文件:

gitfile.sh /path/to/file "MY COMMIT MESSAGE"

我希望这能帮助到一些人,请随意编辑或改进。我不知道最快的方法是什么,但这确实简化了我的代码提交过程使用“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中创建别名: alias gac="git add -A && git commit -m" (我选择称这个快捷方式为“gac”,但你不必这么做) 使用它:gac '你的提交信息在这里'


对于人群中的银背,他们习惯了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.

最简单的方法是:

git commit -am "Your commit message"

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


有人说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,注意“”没有被使用


以下是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>"

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

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