有什么方法可以同时使用这三个命令吗?
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填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!
当前回答
在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
将打开编辑器,一旦你保存消息,它也会推送它。
其他回答
最简单的解决方法是:
git commit -a -m "commit" && git push
Git add已经包含在commit的-a参数中,但如果你想要,你可以把它们都连接起来:
git add . && git commit -a -m "commit" && git push
基于@Gavin的回答:
将lazygit作为一个函数而不是一个别名,这样就可以给它传递一个参数。我已经在我的.bashrc(或.bash_profile如果Mac)中添加了以下内容:
function lazygit() {
git add .
git commit -a -m "$1"
git push
}
这允许您提供一个提交消息,例如
lazygit "My commit msg"
当然,您还可以通过接受更多的参数来进一步增强这一点,比如要推到哪个远程位置,或者哪个分支。
如果你用的是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
我创建了一个专用的bash脚本来自动化所有这些,因为它每次都给我带来很多麻烦。
它看起来是这样的
#!/bin/sh
# Shell Script to add all files, commit them with a commit message from user and then push them to remote GitHub repo
echo "*** Automating Git Add, Commit and Push ***"
#Ask for Username
echo "Enter your GitHub username: "
read username
#Ask for User Github's personal access token
echo "Enter your GitHub personal access token: "
read token
# Ask for repository name
echo "Enter repository name"
read repoName
# Check if repository exists at GitHub
curl "https://api.github.com/repos/${username}/${repoName}.git"
# If repository exits then
if [ $? -eq 0 ]; then
cd $repoName
# Display unstaged files
git status
git remote set-url origin https://${token}@github.com/${username}/${repoName}.git
# If there are any uncommited and unstatged files, ask user to commit them
if [ "$(git status --porcelain)" ]; then
echo "There are uncommited and unstatged files. Commit them before pushing"
echo "Enter commit message"
read commitMessage
git add .
git commit -m "$commitMessage"
git push
echo "Files pushed to GitHub"
# else push all commited and staged files to remote repo
else
git push
echo "Files pushed to GitHub"
fi
#Echo message if there is no files to commit, stage or push
if [ "$(git status --porcelain)" ]; then
echo "There are no files to commit, stage or push"
fi
else
echo "Repository does not exist"
fi
# End of script
你可以简单地通过制作Script .sh(或任何你想要命名的)BASH Script来使用它,它使用GitHub的个人访问令牌来进行身份验证,如果你还没有一个,你可以找到如何使用这个官方文档。
我希望它能解决你的问题。
我发现这个yolo别名是惊人的,甚至提交一个随机的评论,而我是懒惰的提交。它在开箱即用时工作得非常好,所以我只做git yolo,所有的更改都会自动推送。