gpt4 book ai didi

Git:切换到已 stash 更改的分支时发出警告

转载 作者:太空狗 更新时间:2023-10-29 14:27:06 46 4
gpt4 key购买 nike

有没有办法让 git 在切换到已 stash 更改的分支时自动警告您?

我正在寻找类似的东西:

$ git checkout my-branch
Switched to branch 'my-branch'
Stashed changes present: stash@{0}: WIP on my-branch: 836b45a My HEAD commit

只是为了让我在几天后回到项目时不会忘记我已经在分支机构开始的工作。

最佳答案

分支没有“stash ”。

存储只是一个补丁列表,您可以将其应用到任何您想要的地方。

How about appending the warning to a more branch-neutral command like git status then?

你有commit 2414b45 (git 1.6.4,2009 年 6 月)

Show presence of stashed changes in bash prompt.

Add a '$' in the __git_ps1 output to show stashed changes are present, when GIT_PS1_SHOWSTASHSTATE is set to a nonempty value.

The code for checking if the stash has entries is taken from 'git-stash.sh'.

所以尝试:

export GIT_PS1_SHOWSTASHSTATE=1 # Unix
set GIT_PS1_SHOWSTASHSTATE=1 # Windows

git stash 最初是在 commit f2c66ed 中添加到 git 中的(git 1.5.3,2007 年 6 月)作者:Nanako Shiraishi。

这只是一个最近的 git(2.4.2,2014 年 4 月,commit ed178ef)试图显示一个警告,只关于你当前的索引(不管你当前的分支):

Cannot apply stash: Your index contains uncommitted changes.

stash: require a clean index to apply

If you have staged contents in your index and run "stash apply", we may hit a conflict and put new entries into the index. Recovering to your original state is difficult at that point, because tools like "git reset --keep" will blow away anything staged. We can make this safer by refusing to apply when there are staged changes.

It's possible we could provide better tooling here, as "git stash apply" should be writing only conflicts to the index (so we know that any stage-0 entries are potentially precious).
But it is the odd duck; most "mergy" commands will update the index for cleanly merged entries, and it is not worth updating our tooling to support this use case which is unlikely to be of interest (besides which, we would still need to block a dirty index for "stash apply --index", since that case would be ambiguous).

这已在 commit 1937610 中恢复(git 2.4.6,2015 年 6 月)不过。


关于Git:切换到已 stash 更改的分支时发出警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33596212/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com