Git状态拾取父文件夹的文件

时间:2012-03-21 21:46:31

标签: git

我刚刚在htdocs/project创建了一个新项目,当我使用状态来获取该文件夹中的文件时,它列出了htdocs/project中包含的文件和目录,但它也列出了htdocs的所有文件夹和子项。

例如:

# Changes not staged for commit:
#    modified:    ../otherproject/index.php
#    modified:    ../project3/index.php

# Untracked files:
#    ../otherproject/blah.txt
#    ../project3/img/lol.jpg

如果有帮助我使用“Git Bash Here”选项将我的Git目录更改为htdocs/project

3 个答案:

答案 0 :(得分:4)

'htdocs'本身是一个git repo吗?

ls htdocs/.git

如果是这样,那就解释了你所看到的 - 一个git repo里面没有另一个回购。

(作为答案而不是评论发布,因为我没有足够的柿子。)

编辑:基于下面的讨论,这似乎是问题所在。根据{{​​3}}:

Making a Subdirectory the New Root

Suppose you’ve done an import from another source control system and have subdirectories
that make no sense (trunk, tags, and so on). If you want to make the trunk subdirectory be 
the new project root for every commit, filter-branch can help you do that, too:

$ git filter-branch --subdirectory-filter trunk HEAD

Rewrite 856f0bf61e41a27326cdae8f09fe708d679f596f (12/12)
Ref 'refs/heads/master' was rewritten
Now your new project root is what was in the trunk subdirectory each time. Git will also 
automatically remove commits that did not affect the subdirectory.

我自己没有这样做,所以希望有志愿者会有一些经历。

答案 1 :(得分:1)

从我收集的内容来看,听起来您希望拥有多个git存储库,每个存储库代表一个项目,在看起来像是一个虚拟主机目录中并排展开。

从一些实验(以及其他答案的确认)看来,好像您已在htdocs中创建了一个git存储库,而htdocs/project中不存在一个存储库。 htdocs/otherprojecthtdocs/project3中可能有也可能没有git存储库。

假设您希望保留在当前htdocs存储库中的提交历史记录,您可以安全地删除htdocs/.git目录,并在htdocs/project和其他项目目录中创建新存储库

否则,如果您确实希望保留提交历史记录,则必须完成一些工作。我将首先备份htdocs目录,以防万一。从那里,我将删除除htdocs目录之外的htdocs/project的所有子目录,并将这些更改添加到索引中。接下来,我将htdocs/project目录的内容移动到存储库的根目录(到htdocs),并将这些更改添加到索引中。最后,我将删除htdocs/project目录,进行更改并提交。请注意,如果htdocs目录中的任何文件与htdocs/project目录中的文件名相同,那么在提交移动htdocs/project内容之前,可以通过额外提交来节省一些麻烦。 1}}目录。在那里,您只需将htdocs重命名为project,创建新的htdocs目录,然后将project移至htdocs。最后,只需将备份的项目目录移动到新的htdocs目录中。

答案 2 :(得分:0)

git status始终列出存储库中相对于当前位置的所有文件。这意味着您的存储库位于htdocs而不是htdocs / project