有什么方法可以同时使用这三个命令吗?
git add .
git commit -a -m "commit" (do not need commit message either)
git push
有时我只改变一个字母,CSS填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!
有什么方法可以同时使用这三个命令吗?
git add .
git commit -a -m "commit" (do not need commit message either)
git push
有时我只改变一个字母,CSS填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!
当前回答
在lazygit答案的基础上,下面的解决方案添加了一个用户检查,以在推送之前验证更改。如果取消,它将恢复命令。当且仅当本地回购发生变化时,所有这些都会发生。
### SAFER LAZY GIT
function lazygit() {
git add .
if git commit -a -m "$1"; then
read -r -p "Are you sure you want to push these changes? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
git push
;;
*)
git reset HEAD~1 --soft
echo "Reverted changes."
;;
esac
fi
}
其他回答
虽然我同意韦恩·沃纳的怀疑,但从技术上讲,这是一种选择:
git config alias.acp '! git commit -a -m "commit" && git push'
它定义了一个别名,用于运行提交和推送。使用它作为git acp。请注意,这样的“shell”别名总是从git存储库的根目录运行。
另一种选择可能是编写一个执行推送的post-commit钩子。
哦,顺便说一下,您确实可以将参数传递给shell别名。如果你想传递一个自定义提交消息,可以使用:
git config alias.acp '! acp() { git commit -a -m "$1" && git push ; } ; acp'
(当然,现在,你需要给出一个提交消息:git acp“我的消息在这里!”)
在Linux/Mac中,这个非常实用的选项也可以工作
git commit -am "IssueNumberIAmWorkingOn --hit Enter key
> A detail here --Enter
> Another detail here --Enter
> Third line here" && git push --last Enter and it will be there
如果你正在处理一个本地创建的新分支,使用git push -u origin branch_name来更改git push片段
如果你想在系统编辑器中编辑你的提交信息,那么
git commit -a && git push
将打开编辑器,一旦你保存消息,它也会推送它。
我为命令执行了这个.sh脚本
#!/bin/sh
cd LOCALDIRECTORYNAME/
git config --global user.email "YOURMAILADDRESS"
git config --global user.name "YOURUSERNAME"
git init
git status
git add -A && git commit -m "MASSAGEFORCOMMITS"
git push origin master
上面的脚本有一些问题:
Shift“删除”参数$1,否则,“push”将读取它并“误解它”。
我的建议:
Git配置——全局别名。acpp”!git add -A && branchatu="$(git symbol -ref HEAD 2>/dev/null)"& & branchatu = $ {branchatu # # refs /头/} && git commit -m "$1" && shift && git pull -u origin $branchatu && git Push -u origin $branchatu'
基于@Gavin的回答:
将lazygit作为一个函数而不是一个别名,这样就可以给它传递一个参数。我已经在我的.bashrc(或.bash_profile如果Mac)中添加了以下内容:
function lazygit() {
git add .
git commit -a -m "$1"
git push
}
这允许您提供一个提交消息,例如
lazygit "My commit msg"
当然,您还可以通过接受更多的参数来进一步增强这一点,比如要推到哪个远程位置,或者哪个分支。