如何让 GIT_PS1_SHOWDIRTYSTATE 不针对裸存储库运行?
所以我为我安装的 git 设置了 bash 自动完成功能,这太棒了。但是,我有一个裸存储库,我偶尔需要直接与之交互(例如,git reset
),并且每当我 cd
进入裸存储库时, GIT_PS1_SHOWDIRTYSTATE
设置我必须向我显示正常工作树运行的状态,并且我看到此消息:
致命:此操作必须在工作树中运行
它是,我想,努力奔跑针对该存储库的 git status ,但由于是裸露的,它会报告错误。
我希望每次在我的裸仓库中执行任何操作时都不会看到该错误;它已经让我失望了好几次了。
So I've set up bash autocompletion for my install of git, and that rocks. However, I've got a bare repo that I occasionally have to directly interface with (git reset
, for example), and any time I cd
into the bare repo, the GIT_PS1_SHOWDIRTYSTATE
setting I have to show me the status of my normal working trees runs, and I see this message:
fatal: This operation must be run in a work tree
It is, I think, trying to run a git status
against that repo, but being bare, it reports an error.
I'd love to not see that error every time I do anything in my bare repo; it's thrown me off a few times already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在您的存储库上执行 git config core.bare 来检查它是否是裸露的。如果存储库是使用 git init --bare 创建的,那么这是可靠的。对于裸存储库,它将返回
true
,对于其他存储库,它将返回false
。您可以使用它来过滤调整您的完成脚本。You can do a
git config core.bare
on your repo to check whether it is bare or not. This is reliable if the repository was created usinggit init --bare
. It will returntrue
for bare repositories andfalse
for others. You can use this to filter adjust your completion script as appropriate.所以,事实证明,使用这个要点正是导致它无法正常工作的原因。我设置了
.bash_profile
来加载安装 Git 时附带的 bash 补全,一切都很好。谢谢!So, as it turned out, using that gist was exactly the reason for this not working correctly. I set my
.bash_profile
to load the bash completion that came with my install of Git, and all is well. Thanks!