检查是否有"git stash"藏东西 [英] Check if "git stash" stashed anything

查看:93
本文介绍了检查是否有"git stash"藏东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows Command脚本,旨在将 dev 分支合并到项目分支中.首先,它会读取当前的分支名称,存储更改,获取并合并dev和project分支,然后切换回原始分支并弹出存储.

I have a Windows Command script designed to merge the dev branch into a project branch. It starts by reading the current branch name, stashing changes, fetching and merging the dev and project branches, then switches back to the original branch and pops the stash.

问题是存储可能没有任何更改.这会将先前的存储留在堆栈的顶部.当到达脚本末尾并弹出存储时,它将弹出与当前分支无关的先前存储.

The issue is there might not be any changes to stash. This leaves the previous stash at the top of the stack. When it gets to the end of the script and pops the stash, it's popping the previous stash which is unrelated to the current branch.

Set SourceBranch=dev
Set ProjectBranch=project

:: Stash current changes.
For /F "tokens=1,2" %%a In ('Git branch -q') Do If "%%a"=="*" Set CurrentBranch=%%b
Git stash save -u

:: Pull latest source branch.
Git checkout %SourceBranch%
Git pull
For /F "tokens=1,3" %%a In ('Git branch -q -v') Do If "%%a"=="*" Set MergeHash=%%b

:: Merge source into project branch.
Git checkout %ProjectBranch%
Git pull
Git merge --commit %MergeHash%||Exit 1

:: Return to original branch.
Git checkout %CurrentBranch%
Git stash pop

如何获取Git stashGit status的反馈以确定我是否需要弹出存储卡?

How can I get feedback from Git stash or Git status to determine whether I need to pop the stash?

推荐答案

git stash允许您提供消息.您可以将生成的令牌用作消息,以便知道它不会与其他git stash消息冲突.

git stash allows you to provide a message. You can use a generated token as your message so that you know it won't conflict with other git stash messages.

然后,当您要检查是否弹出时,只需检查git stash list输出中是否包含您的令牌.如果是这样,请弹出存储卡.

Then, when you want to check whether or not to pop, simply check if the git stash list output contains your token. If so, pop the stash.

这篇关于检查是否有"git stash"藏东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆