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

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

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


当前回答

如果文件已经被跟踪,那么你不需要运行git add,你可以简单地写git commit -am 'your message'

如果不想写提交消息,可以考虑这样做

Git commit——allow-empty-message -am "

其他回答

在.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'

是否会添加某些文件更改,并使用自定义提交消息

如果你用的是fish shell(基于btse的答案):

将该文件保存在` ~/。Config /fish/functions'为'quickgit.fish'。如果目录不存在,请创建该目录。 ”——git-dir = $ PWD /。确保我们在调用函数的git项目上运行git命令

function quickgit # This is the function name and command we call
    git --git-dir=$PWD/.git add . # Stage all unstaged files
    git --git-dir=$PWD/.git commit -a -m $argv # Commit files with the given argument as the commit message
    git --git-dir=$PWD/.git push # Push to remote
end

重新启动终端,导航到项目,进行更改,现在您可以调用“quickgit”示例消息“”。 更改现在将被添加、提交和推送:)。

也可以在这里找到Gist: https://gist.github.com/Abushawish/3440a6087c212bd67ce1e93f8d283a69

在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 

将打开编辑器,一旦你保存消息,它也会推送它。

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

我认为你可能误解了git设计的工作流程。(为了澄清/纠正我在评论中的意思,你不需要git add .,因为commit -a通常具有相同的目的-如果文件已经添加,则添加任何尚未登台的更改)

通常你会这样做:

# make some changes
$ git commit -a -m "Changed something"
# make some more changes
$ git commit -a -m "Changed something else"

清洗,冲洗,重复,直到你完成了功能X,或者你在一个停止点,或者你只是想让其他人看到你所做的。然后你做了

$ git push

Git不是SVN——但似乎您正试图将它作为SVN来使用。您可能会在本文末尾找到一些有用的参考资料。