有什么方法可以同时使用这三个命令吗?

git add .
git commit -a -m "commit" (do not need commit message either)
git push

有时我只改变一个字母,CSS填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!


当前回答

我在.bash_profile中使用它

gitpush() {
    git add .
    git commit -m "$*"
    git push
}
alias gp=gitpush

它像这样执行

gp A really long commit message

不要忘记运行source ~/。保存别名后的Bash_profile。

其他回答

您可以使用bash脚本,设置别名来启动任何命令或一组命令

git commit -am "your message" && git push 

对于MAC VSC用户来说,最好的设置是:

1)按'shift+cmd+P'并输入:

Shell Command: install 'code' command in PATH

按ENTER(这将安装代码命令,以便轻松获得bash_profile)

2)你现在可以运行:code ~/。打开空的Bash_profile

3)在那里输入一个新函数:

function lazygit() {
    git add .
    git commit -m "$*"
    git push
}

4)现在重启VSC

5)进行更改,保存并输入lazygit message同时运行这三个命令

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

加入~/。Bash_profile用于添加、提交和推送:

function g() { git commit -a -m "$*"; git push; }

用法:

g your commit message
g your commit message 'message'

不需要引号,尽管不能在提交消息中使用分号或括号(允许使用单引号)。如果你想使用以上任何一种方法,只需在你的邮件中加上双引号,例如:

g "your commit message; (message)"

要在你的消息中创建评论,请:

g "your commit message:
> your note"

还有一个函数用于以类似的方式添加和提交:

function c() { git add --all; git commit -m "$*"; }

和g函数的工作原理完全一样并且有相同的约束条件。用c代替。 如。

c your commit message

你也可以添加一个别名来推送到远程:

alias p='git push'

用法:

p

这相当于2个字母,c和p,您在使用git存储库时使用。或者你可以用g来代替只用一个字母。

别名和函数的完整列表: https://gist.github.com/matt360/0c5765d6f0579a5aa74641bc47ae50ac

我使用批处理文件:

@ECHO OFF
SET /p comment=Comment:
git add *
git commit -a -m "%comment%"
git push