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

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

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


当前回答

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中设置为别名:

$ alias lazygit="git add .; git commit -a -m '...'; git push;";

叫它:

$ lazygit

(要使这个别名永久存在,你必须将它包含在你的.bashrc或.bash_profile中)

我为命令执行了这个.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

你可以试试gitu。

第一次(必须安装node js):

npm install -g git-upload

后:

gitu COMMIT_MSG

同时发出这三个命令。

好处是,当您重新安装系统或当您想在不同的计算机上执行此操作时,您不必担心,并且不需要修改文件。 这也适用于不同的平台(不只是Linux和Mac,也可以在命令提示符下的Windows,如cmd和powershell),只是你必须安装npm和nodejs(当然是git)。

在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
}

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

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