简体   繁体   English

如何制作bash脚本以上传到git

[英]How to make a bash script for uploading to git

I am using mac osx, and would like to make a simple bash script for uploading changed files to my github repository. 我正在使用Mac OS X,并想制作一个简单的bash脚本,用于将更改的文件上传到我的github存储库。

It should ask for my comments to the files that i'm committing something like: 它应该征求我对我提交的文件的注释,例如:

git add .
git commit -m 'prompt for comments'
git push origin master

I don't know how to make the script, i just want to do it via terminal with a single command. 我不知道如何制作脚本,我只想通过终端用一个命令来完成。

any help would be much appreciated. 任何帮助将非常感激。

I do know how to make aliases in my .bash_profiles though :-) 我确实知道如何在.bash_profiles中创建别名:-)

Thanks. 谢谢。

You may try: 您可以尝试:

#!/bin/bash  
git add .  
read -p "Commit description: " desc  
git commit -m "$desc"
git push origin master

Here's a super simple solution that's more generic than bash (more portable): 这是一个比bash更通用(更可移植)的超简单解决方案:

#!/bin/sh
printf "Commit msg: "
read msg
git commit -am "$msg"
git push origin master

It doesn't do git add to add new files but -a adds tracked files to be staged for commit. 它不执行git add来添加新文件,而是-a添加要暂存的跟踪文件。 This is often what one wants. 这通常是人们想要的。 If you really want to do git add . 如果您真的想做git add . just add that line and remove the a from options to git commit . 只需添加该行并从git commit选项中删除a from即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM