有什么方法可以同时使用这三个命令吗?
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 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来使用。您可能会在本文末尾找到一些有用的参考资料。
其他回答
这个结果 -试试这个:简单的脚本一个命令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
我最终在我的.gitconfig文件中添加了一个别名:
[alias]
cmp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"
用法:git cmp "Long commit message goes here"
添加所有文件,然后使用提交消息的注释并将其推到原点。
我认为这是一个更好的解决方案,因为你可以控制提交消息是什么。
别名也可以从命令行定义,这将它添加到你的.gitconfig:
git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f'
我创建了一个专用的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的个人访问令牌来进行身份验证,如果你还没有一个,你可以找到如何使用这个官方文档。
我希望它能解决你的问题。
如果你使用VSCode,你可以下载这个扩展,它会让你在一个简单的键盘快捷方式。