有什么方法可以同时使用这三个命令吗?
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填充之类的。不过,我必须编写所有三个命令来推动更改。有许多项目,我只是一个推动者,所以这个命令将是了不起的!
当前回答
这个结果 -试试这个:简单的脚本一个命令git添加,git提交和git推送
在Windows上打开CMD并粘贴此答案
Git提交-m“你的消息”。git push origin master
这个例子我的图片截图: https://i.stack.imgur.com/2IZDe.jpg
其他回答
由于问题没有指定哪个shell,下面是基于前面答案的shell版本。这将放入shell别名文件,该文件可能在~/.emacs中。d/eshell/alias我已经添加了第一部分z https://github.com/rupa/z/,它可以让你快速cd到一个目录,这样无论你的当前目录是什么都可以运行。
alias census z cens; git add .; git commit -m "fast"; git push
加入~/。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
请看我的回答,我把所有的东西都加到了一行中
alias gitcomm="echo 'Please enter commit message';read MSG ;git add --all;git commit -am=$MSG;git push"
我创建了一个专用的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的个人访问令牌来进行身份验证,如果你还没有一个,你可以找到如何使用这个官方文档。
我希望它能解决你的问题。
这非常适合命令分组。
分组命令
{列表;} 将命令列表放在花括号之间会导致该列表在当前shell上下文中执行。没有创建子shell。列表后面必须有分号(或换行符)。
legit(){ git add --all; git commit -m "$1"; git push origin master; }
legit 'your commit message here'