有什么方法可以同时使用这三个命令吗?
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填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!
当前回答
基于@Gavin的回答:
将lazygit作为一个函数而不是一个别名,这样就可以给它传递一个参数。我已经在我的.bashrc(或.bash_profile如果Mac)中添加了以下内容:
function lazygit() {
git add .
git commit -a -m "$1"
git push
}
这允许您提供一个提交消息,例如
lazygit "My commit msg"
当然,您还可以通过接受更多的参数来进一步增强这一点,比如要推到哪个远程位置,或者哪个分支。
其他回答
编写一个名为gitpush.sh的小脚本,并将其添加到~目录中。
echo $1
git add .
git commit -m "$1"
git push
现在在~/中添加一个别名。Bashrc如下:
alias gitpush='~/gitpush'
现在从任何git存储库只写gitpush "message"。
在bash中设置为别名:
$ alias lazygit="git add .; git commit -a -m '...'; git push;";
叫它:
$ lazygit
(要使这个别名永久存在,你必须将它包含在你的.bashrc或.bash_profile中)
你好,你只需要添加unalias [nano或vi] ~/.bashrc
echo Enter You commit message && read msg && git add . && git commit -m "$msg" && git push origin main
我创建了一个专用的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的个人访问令牌来进行身份验证,如果你还没有一个,你可以找到如何使用这个官方文档。
我希望它能解决你的问题。
如果文件已经被跟踪,那么你不需要运行git add,你可以简单地写git commit -am 'your message'
如果不想写提交消息,可以考虑这样做
Git commit——allow-empty-message -am "