我能做点什么吗
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不添加。什么?
当前回答
我有这个函数在我的。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 add -A && git commit -m "comment"
我做一个壳层
#!/bin/sh
clear
git add -A
git commit -a -m "'$*'"
例如保存为git.sh,然后调用:
sh git.sh your commit message
你可以使用
git commit -am "[comment]" # best solution
or
git add . && git commit -m "[comment]"
以下是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>"
我希望这能帮助到一些人,请随意编辑或改进。我不知道最快的方法是什么,但这确实简化了我的代码提交过程使用“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