首页 > 解决方案 > Git:--git-dir 将所有文件显示为丢失

问题描述

我有两个具有相同子模块的非常相似的存储库。目录结构:

vss
vss/rcv-nginx
rgw
rgw/rcv-nginx

当从rgw目录请求状态时(只有它!),它表明所有文件都被删除。其他类似项目不会发生这种情况。

git status 命令来了:

# On vss
peter@peterpc:~/git/vss$ git --git-dir=rcv-nginx/.git status
On branch dev
Your branch is up-to-date with 'origin/dev'.
nothing to commit, working directory clean

# On vss/rcv-nginx
peter@peterpc:~/git/vss$ cd rcv-nginx/
peter@peterpc:~/git/vss/rcv-nginx$ git status
On branch dev
Your branch is up-to-date with 'origin/dev'.
nothing to commit, working directory clean

# On rgw:
peter@peterpc:~/git/rgw$ git --git-dir=rcv-nginx/.git status
On branch feature-rcv-11870_openresty-nginx
Your branch is up-to-date with 'origin/feature-rcv-11870_openresty-nginx'.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitlab/merge_request_templates/Bug.md
        modified:   .gitlab/merge_request_templates/Feature.md
        deleted:    .idea/runConfigurations/Render_Dyrka_Configs.xml
        ...
        (all files marked as missing)

# on rgw/rcv-nginx
peter@peterpc:~/git/rgw$ cd rcv-nginx/
peter@peterpc:~/git/rgw/rcv-nginx$ git status
On branch feature-rcv-11870_openresty-nginx
Your branch is up-to-date with 'origin/feature-rcv-11870_openresty-nginx'.
nothing to commit, working directory clean

附言

我已经检查了这个问题(git --git-dir not working as expected)并且我知道解决方法,但问题仍然存在——为什么 git 在类似项目中表现不同?

标签: git

解决方案


可能是因为之前在这个目录中只有 rcv-nginx 是一个符号链接,后来我把它改成了独立的,但 Git 缓存仍然存在。


推荐阅读