shell获取git最近一次提交信息_击/ Shell脚本函数来验证的Git标签或提交存在,并已经被推到远程仓库...

I wanted to get this question out there to see if I'm doing this right. The following script works except for checking to see if the commit has been pushed to a remote repo which I can't find the right command for:

#!/bin/bash

set -e # fail on first error

verify_git_ref() {

log "Verifying git tag or commit: \"$1\" ...."

if git show-ref --tags --quiet --verify -- "refs/tags/$1"

then

log_success "Git tag \"$1\" verified...."

GIT_TAG_OR_REF=$1

return 0

elif git rev-list $1>/dev/null 2>&1

then

log_success "Git commit \"$1\" verified...."

GIT_TAG_OR_REF=$1

return 0

else

log_error "\"$1\" is not a valid tag or commit, you must use a valid tag or commit in order for this script to continue"

return 1

fi

}

解决方案

Checking whether a remote has a given tag is pretty simple - you should just need to parse the output of git ls-remote --tags to see if it contains your tag.

Checking if a given commit is there is a little trickier. Everything is ref-based. Do you know what ref it should be reachable from? If you do, you should probably just fetch that ref and check locally if the commit is an ancestor of it. That is, fetch master from origin and see if the commit's on origin/master.

You could also try using git push -n to do a dry run of pushing the commit to that branch, and see what happens - if it's a no-op, the commit's already on the branch.

If you don't know what branch it should be on... you'll probably just have to fetch and check them all.

git 脚本 bash shell 是一个用于自动化执行 git 操作的脚本,在当前目录下,使用 git pull 命令自动拉取所有 git 仓库的更新。该脚本可以在 Windows 上的 Git Bash 环境中运行,因为 Git Bash 是一个 mingw64 的环境,可以运行 Linux 的大部分命令。 该脚本的实现主要包括以下几个步骤: 1. 定义了一个函数 git_pull_all,该函数用于遍历当前目录下的所有子目录。 2. 在遍历过程中,对每个子目录执行以下操作: a. 切换到当前子目录:cd $cur_dir b. 显示 git 状态:git status c. 清除未跟踪文件和文件夹:git clean -xdf d. 更新子模块:git submodule update --init --force --recursive e. 拉取最新代码:git pull 3. 输出运行结果。 要运行该脚本,只需在 Git Bash 命令行中输入 ./git_pull_all.sh。 请注意,在 Windows 上运行 shell 脚本需要先安装好 Git,并配置好环境。你可以参考提供的教程来进行 Git 的安装和配置。 总结来说,git 脚本 bash shell 是一个用于自动拉取当前目录下所有 git 仓库脚本,可以在 Windows 的 Git Bash 环境中运行。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [git bash shell 脚本 :自动拉取目录下所有的git 仓库](https://blog.csdn.net/tcjy1000/article/details/124786613)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [dotfiles:Git和bash首选项,以及用于在新笔记本电脑上进行设置的脚本](https://download.csdn.net/download/weixin_42102634/15497989)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [windows使用git bash运行shell脚本](https://blog.csdn.net/Amber__py/article/details/115199391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值