如何让Intellij只存在于其他分支的模块在切换分支时不可见?

问题描述 投票:0回答:1

这个问题困扰我很久了。如下图所示,模块“crud”只存在于另一个分支中,但是当我切换分支时,仍然可以看到这个文件夹。是否有任何配置或操作可以在切换分支时自动阻塞不存在的模块? problem-image

希望有人能解决我的问题

git intellij-idea
1个回答
0
投票

切换分支时,Git 不会删除

.gitignore
中列出的任何内容。如果忽略
crud
中的任何内容,git 将不会删除该目录。

但是,它确实允许使用

Hooks
checkout 之后运行自定义代码。您可以创建一个
post-checkout
挂钩(位于
.git/hooks/post-checkout
中,如果
crud
不在
HEAD
中,则删除它。

您可以使用

HEAD
检查
git ls-tree
是否包含目录
:

#!/bin/bash

# you can put a script like that in .git/hooks/post-checkout

if [ -z "$(git ls-tree -d HEAD:crud)" ] then
    echo "deleting crud directory"
    rm -rf crud
fi
© www.soinside.com 2019 - 2024. All rights reserved.