如何追踪未追踪的内容?
看到下面的实线我的原始问题。
我的本地目录中有一个未跟踪的文件夹。 当我运行git status
,我得到:
Changed but not updated:
modified: vendor/plugins/open_flash_chart_2 (modified content, untracked content)
当我输入git add vendor/plugins/open_flash_chart_2
然后再次尝试git status
时,它仍然表示未跟踪。 这是怎么回事?
以下是我最近半小时的简单总结:
发现我的Github回购没有跟踪我的vendor/plugins/open_flash_chart_2
插件。 具体来说,没有内容,它在文件夹图标上显示绿色箭头。
尝试git submodule init
No submodule mapping found in .gitmodules for path 'vendor/plugins/open_flash_chart_2'
试过git submodule add git://github.com/korin/open_flash_chart_2_plugin.git vendor/plugins/open_flash_chart_2
vendor/plugins/open_flash_chart_2 already exists in the index
git status
modified: vendor/plugins/open_flash_chart_2 (untracked content)
在我的资源库/本地目录中找到任何名为.gitmodules
文件,但找不到它。
我需要做些什么才能让我的子模块正常工作,以便git可以开始正确跟踪?
这可能是无关的(我把它包括在它的情况下),但每次我键入git commit -a
而不是我通常的git commit -m "my comments"
,它会引发一个错误:
E325: ATTENTION
Found a swap file by the name ".git.COMMIT-EDITMSG.swp"
dated: Thu Nov 11 19:45:05 2010
file name: c:/san/project/.git/COMMIT_EDITMSG
modified: YES
user name: San host name: San-PC
process ID: 4268
While opening file ".gitCOMMIT_EDITMSG"
dated: Thu Nov 11 20:56:09 2010
NEWER than swap file!
Swap file ".git.COMMIT_EDITMSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
Swap file ".git.COMMIT_EDITMSG.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
我在Github是一个完整的新手,尽管试图通过文档,但我对这些特殊问题感到困惑。 谢谢。
您已将vendor/plugins/open_flash_chart_2
添加为“gitlink”条目,但从未将其定义为子模块。 实际上,您使用的是git子模块使用的内部功能(gitlink条目),但您并未使用子模块功能本身。
你可能做了这样的事情:
git clone git://github.com/korin/open_flash_chart_2_plugin.git vendor/plugins/open_flash_chart_2
git add vendor/plugins/open_flash_chart_2
这最后的命令是问题。 目录vendor/plugins/open_flash_chart_2
从一个独立的Git仓库开始。 通常这样的子库会被忽略,但如果你告诉git add显式地添加它,那么它会创建一个指向子库的HEAD提交而不是添加目录内容的gitlink条目。 如果git add会拒绝创建这样的“半子模块”,那可能会很好。
普通目录在Git中表示为树对象; 树对象为它们包含的对象提供名称和权限(通常分别为其他树和blob对象 - 目录和文件)。 子模块被表示为“gitlink”条目; gitlink条目只包含子模块HEAD提交的对象名称(哈希)。 gitlink的提交的“源代码库”在.gitmodules
文件中指定(在子模块初始化后指定.git/config
文件)。
您拥有的是指向特定提交的条目,而不记录该提交的源存储库。 你可以通过将你的gitlink变成一个合适的子模块来解决这个问题,或者通过删除gitlink并用“普通”内容(普通文件和目录)替换它来解决这个问题。
把它变成一个合适的子模块
将vendor/plugins/open_flash_chart_2
正确定义为子模块的.gitmodules
是.gitmodules
文件。 通常情况下(如果你还没有添加它作为裸露的gitlink条目),你可以使用git submodule add
:
git submodule add git://github.com/korin/open_flash_chart_2_plugin.git vendor/plugins/open_flash_chart_2
如你所见,如果路径已经存在于索引中,这将不起作用。 解决方法是暂时从索引中删除gitlink条目,然后添加子模块:
git rm --cached vendor/plugins/open_flash_chart_2
git submodule add git://github.com/korin/open_flash_chart_2_plugin.git vendor/plugins/open_flash_chart_2
这将使用您现有的子存储库(即它不会重新克隆源存储库)并创建一个.gitmodules
文件:
[submodule "vendor/plugins/open_flash_chart_2"]
path = vendor/plugins/open_flash_chart_2
url = git://github.com/korin/open_flash_chart_2_plugin.git vendor/plugins/open_flash_chart_2
它也会在你的主存储库的.git/config
(没有path
设置)中做类似的条目。
承诺,你将有一个合适的子模块。 当你克隆版本库(或者推送到GitHub并从那里克隆)时,你应该能够通过git submodule update --init
重新初始化子git submodule update --init
。
用普通内容替换它
下一步假定vendor/plugins/open_flash_chart_2
中的子存储库没有任何要保留的本地历史记录(即,您所关心的只是子存储库的当前工作树,而不是历史记录)。
如果您关心的子存储库中有本地历史记录,那么在下面的第二条命令中删除它之前,您应该备份子存储库的.git
目录。 (还要考虑下面的git子树例子,它保留了子库的HEAD的历史记录)。
git rm --cached vendor/plugins/open_flash_chart_2
rm -rf vendor/plugins/open_flash_chart_2/.git # BACK THIS UP FIRST unless you are sure you have no local changes in it
git add vendor/plugins/open_flash_chart_2
这次添加目录时,它不是一个子存储库,所以文件将被正常添加。 不幸的是,由于我们删除了.git
目录,因此没有一种超级简单的方法可以使源代码库保持最新状态。
您可以考虑使用子树合并。 这样做可以让您轻松地从源存储库中引入更改,同时将文件保留在存储库中(无子模块)。 第三方git subtree命令是围绕子树合并功能的不错包装。
git rm --cached vendor/plugins/open_flash_chart_2
git commit -m'converting to subtree; please stand by'
mv vendor/plugins/open_flash_chart_2 ../ofc2.local
git subtree add --prefix=vendor/plugins/open_flash_chart_2 ../ofc2.local HEAD
#rm -rf ../ofc2.local # if HEAD was the only tip with local history
后来:
git remote add ofc2 git://github.com/korin/open_flash_chart_2_plugin.git
git subtree pull --prefix=vendor/plugins/open_flash_chart_2 ofc2 master
git subtree push --prefix=vendor/plugins/open_flash_chart_2 git@github.com:me/my_ofc2_fork.git changes_for_pull_request
git子树也有一个--squash
选项,可以避免将源代码库的历史记录合并到历史记录中,但仍然可以引入上游更改。
我只是有同样的问题。 原因是因为有一个包含“.git”文件夹的子文件夹。 删除它让git开心。
指出克里斯约翰森与OP聊天的内容(从回复答案中链接出来):
git add vendor/plugins/open_flash_chart_2
#将添加gitlink,内容将保持不受追踪
git add vendor/plugins/open_flash_chart_2/
#注意这个SLASH !!!!
第二种形式将添加它没有gitlink,并且内容是可跟踪的。 .git目录很方便且自动地被忽略。 谢谢克里斯!
链接地址: http://www.djcxy.com/p/92287.html上一篇: How to track untracked content?
下一篇: what causes submodule conflicts in git, and how should they be resolved?