我能做点什么吗
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 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不添加。什么?
当前回答
如果有人想为单个文件“添加并提交”,这是我的情况,我创建了下面的脚本来做到这一点:
#!/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"
其他回答
首先检查你有哪些别名……
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'
只使用:
git commit -m "message" .
注意结尾的"."…也可以是文件/目录的路径
我做一个壳层
#!/bin/sh
clear
git add -A
git commit -a -m "'$*'"
例如保存为git.sh,然后调用:
sh git.sh your commit message
只适应Ales的回答和courtsimas的评论linux bash:
要保持在一行中使用:
Git commit -am "comment"
这一行将添加并提交所有更改到存储库。
只要确保没有git还未拾取的新文件就可以了。否则你需要使用:
Git添加。; Git commit -am "message"
你可以使用
git commit -am "[comment]" # best solution
or
git add . && git commit -m "[comment]"