利用 bash 脚本提高效率 - git push

每次提交都要输重复命令

遂想能否通过脚本来自动执行,省的手动重复输入这三个命令

上网查询,发现可以通过 bash 命令。

概述

利用 git 命令更新代码仓库,普遍三个命令:

git add .
git commit -m "message"
git push origin main

每次提交都要输一遍这三行,于是想到能否通过脚本来自动执行这三个,省的手动重复输入这三个命令。上网查询,发现可以通过 bash 命令。

实现

根据网上教程,编写出以下代码:

# 命名:git_WillCAI2020.bat
@echo off
echo "Introduction: Update the remote repository, written by ruchan"
echo "Steps:"

::注意修改为你自己的仓库地址
echo "1. Move to working directory" 
cd D:\本地仓库路径

echo "2. Display the status of the working directory and staging area" 
git status

echo "3. Start submitting code to the local repository"
git add .
 
echo "4. Commit the changes to the local repository"
set /p message=请输入提交信息:
echo %message%
git commit -m "%message%"
 
echo "5. Push the changes to the remote git server"
git push origin main
 
echo "You have successfully submitted!"
pause

步骤如代码中注释,通俗易懂。

注意修改仓库路径,命名以 bat 结尾,存放位置任意。

执行代码时,还能手动输入待提交信息(利于帮助管理代码)。

使用时双击运行即可。

扩展

还想到能否通过 bash 来执行:

hexo clean && hexo g && hexo s

然后直接把相关命令通过 dos 运行,这是发现结果并不如愿。

于是发现应该先通过 bash 命令启动 git-bash,然后在 Git 中执行 hexo clean && hexo g && hexo s

得到:

@echo off

echo "Introduction: Preview your hexo site locally, written by ruchan"
echo "Steps:"

start C:\git-bash.exe存在路径 --cd=D:\本地仓库路径 -c "hexo clean && hexo g && hexo s"

虽然发现能行,但速度不大满意,还是手动输吧。

参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值