简体   繁体   English

检查“git stash”是否藏匿了什么

[英]Check if “git stash” stashed anything

I have a Windows Command script designed to merge the dev branch into a project branch. 我有一个Windows Command脚本,旨在将dev分支合并到项目分支中。 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

How can I get feedback from Git stash or Git status to determine whether I need to pop the stash? 如何从Git stashGit status获取反馈以确定是否需要弹出存储?

git stash allows you to provide a message. git stash允许您提供消息。 You can use a generated token as your message so that you know it won't conflict with other git stash messages. 您可以使用生成的令牌作为消息,以便您知道它不会与其他git存储消息冲突。

Then, when you want to check whether or not to pop, simply check if the git stash list output contains your token. 然后,当您想要检查是否要弹出时,只需检查git stash list输出是否包含您的令牌。 If so, pop the stash. 如果是这样,请弹出藏匿处。

git stash list #get a listing of all stashes to parse
git stash show -p stash@{0} #replace 0 with number of relevant stash from list

You can git diff and inspect the output. 你可以git diff并检查输出。 If there is none, then there is nothing to stash . 如果没有,那么就没有什么可stash Any issue with that strategy? 该策略有任何问题吗?

On Linux, you can use git stash list | wc -l 在Linux上,您可以使用git stash list | wc -l git stash list | wc -l to count the number of stash entries. git stash list | wc -l计算存储条目的数量。 If there was nothing to stash, then this returns the same before and after your actual git stash . 如果没有任何东西要存储,那么这会在你的实际git stash之前和之后返回相同的内容。 I'm not sure if you can use this on Windows though. 我不确定你是否可以在Windows上使用它。

暂无
暂无

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

相关问题 Git stash:如何查看分支中是否存在隐藏的更改 - Git stash: How to see if there are stashed changes in a branch Git stash 只有在之前成功隐藏时才会弹出 - Git stash pop only if successfully stashed before git stash -> 将隐藏的更改与当前更改合并 - git stash -> merge stashed change with current changes 在 git 中,有没有办法在不应用存储的情况下显示未跟踪的隐藏文件? - In git, is there a way to show untracked stashed files without applying the stash? 当它们被日期描述时,是否可以选择一个git stash? - Is it possible to choose a git stash when they're described by the date stashed? 有没有办法存储当前的 git 索引,`git add -u`,然后将索引恢复到存储的 state? - Is there a way to stash the current git index, `git add -u`, and then restore the index to the stashed state? 如果有任何要弹出的内容,只能调用'git stash pop' - Only call 'git stash pop' if there is anything to pop 我将如何创建一个 git stash 并继续使用我存储的文件? - How would I create a git stash and keep working with the files I have stashed? 有没有更好的方法来执行git stash pop,然后如果我不合并则丢弃隐藏的更改? - Is there a better way of doing a git stash pop and then discard the stashed changes if I don't merge? 跑了'git checkout stash',现在想用我藏匿的当前未附加分支覆盖现有分支 - Ran 'git checkout stash' and now want to overwrite an existing branch with my current unattached branch that i had stashed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM