有什么方法可以同时使用这三个命令吗?
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填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!
当前回答
请看我的回答,我把所有的东西都加到了一行中
alias gitcomm="echo 'Please enter commit message';read MSG ;git add --all;git commit -am=$MSG;git push"
其他回答
macOS用户:
打开您的终端或iTerm2或您使用的其他终端。 使用~/命令移动到用户配置文件文件夹。它是.bash_profile文件的默认文件夹:
输入nano. bash_profile这个命令将在最容易使用的终端nano文本编辑器中打开.bash_profile文档(如果它还不存在,也可以创建它)。 现在您可以对文件进行简单的更改。粘贴以下代码行来更改终端提示符:
function lazygit() {
git add .
git commit -a -m "$1"
git push
}
现在通过输入ctrl + o保存您的更改,并点击返回保存。然后输入ctrl + x退出nano。 现在我们需要激活您的更改。输入source .bash_profile(或。~/.bash_profile)并注意提示符的变化。 在iTerm2的Preferences/Profiles/General/Command中设置为Login Shell并在start时发送文本到source ~/.bash_profile。因此,您不需要在每次macOS重新启动后手动进行设置。
凭证:https://natelandau.com/my-mac-osx-bash_profile
在.bashrc中定义函数
function gitall() {
file=${1:-.}
comment=${2:-update}
echo $file
echo $comment
git add $file && git commit -m '$comment' && git push origin master
}
在你的终端
gitall
默认gitall将添加当前git repo中的所有内容
gitall some-file-to-add 'update file'
是否会添加某些文件更改,并使用自定义提交消息
如果你用的是Mac电脑:
打开终端,输入cd ~/进入主文件夹 输入touch .bash_profile创建新文件。 使用您最喜欢的编辑器编辑.bash_profile(或者您可以直接键入 open -e .bash_profile在TextEdit中打开它)。 复制并粘贴下面的文件:
函数lazygit() { Git添加。 Git commit -m "$1" git推 }
在这之后,重启你的终端,简单地添加,提交和推送一个简单的命令,例如:
lazygit "This is my commit message"
我使用批处理文件:
@ECHO OFF
SET /p comment=Comment:
git add *
git commit -a -m "%comment%"
git push
在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
}