如何跟踪未跟踪的内容?
请参阅下面的实线了解我原来的问题。
我的本地目录中有一个未跟踪的文件夹。当我运行 git status 时,我得到:
Changed but not updated:
modified: vendor/plugins/open_flash_chart_2 (modified content, untracked content)
当我输入 git addvendor/plugins/open_flash_chart_2 然后再次尝试 git status 时,它仍然显示未跟踪。这是怎么回事?
以下是我最近半个小时的简单总结:
发现我的 Github 存储库没有跟踪我的
vendor/plugins/open_flash_chart_2
插件。具体来说,没有内容,并且文件夹图标上显示绿色箭头。尝试了
git子模块初始化
在 .gitmodules 中找不到路径“vendor/plugins/open_flash_chart_2”的子模块映射
尝试
git submodule add git://github.com/korin/open_flash_chart_2_plugin.gitvendor/plugins/open_flash_chart_2
vendor/plugins/open_flash_chart_2 已存在于索引中
git状态
< /p>已修改:vendor/plugins/open_flash_chart_2(未跟踪内容)
在我的存储库/本地目录中寻找任何名为
.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 ".git\COMMIT_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 的新手,尽管尝试查看文档,但我还是对这些特定问题感到有点困惑。谢谢。
See below the solid line for my original question.
I have a folder in my local directory that is untracked. When I run git status
, I get:
Changed but not updated:
modified: vendor/plugins/open_flash_chart_2 (modified content, untracked content)
When I type git add vendor/plugins/open_flash_chart_2
then try git status
again, it still says untracked. What's going on?
Here is a simple summary of my latest half hour:
Discovered that my Github repo is not tracking my
vendor/plugins/open_flash_chart_2
plugin. Specifically, there's no content and it's showing a green arrow on the folder icon.Tried
git submodule init
No submodule mapping found in .gitmodules for path 'vendor/plugins/open_flash_chart_2'
Tried
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)
Hunted for any file named
.gitmodules
in my repository/local directory but couldn't find one.
What do I have to do to get my submodules working so git can start tracking properly?
This may be unrelated (I include it in case it helps), but every time I type git commit -a
rather than my usual git commit -m "my comments"
, it throws up an error:
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 ".git\COMMIT_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:
I am a complete newbie at Github and despite trying to go through the documentation, I'm a bit stumped by these particular problems. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
您已将
vendor/plugins/open_flash_chart_2
添加为“gitlink”条目,但从未将其定义为子模块。实际上,您正在使用 git 子模块 使用的内部功能(gitlink 条目),但您没有使用子模块功能本身。您可能做了这样的事情:
最后一个命令就是问题所在。目录
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
文件。通常(如果您尚未将其添加为裸 gitlink 条目),您只需使用 git submodule add :正如您所发现的,如果路径已存在于索引中,则这将不起作用。解决方案是暂时从索引中删除 gitlink 条目,然后添加子模块:
这将使用您现有的子存储库(即不会重新克隆源存储库)并暂存
.gitmodules
文件如下所示:它还会在主存储库的
.git/config
中创建类似的条目(没有path
设置)。提交它,您将拥有一个合适的子模块。当您克隆存储库(或推送到 GitHub 并从那里克隆)时,您应该能够通过 git submodule update --init 重新初始化子模块。
将其替换为纯内容
下一步假设
vendor/plugins/open_flash_chart_2
中的子存储库没有任何您想要保留的本地历史记录(即您关心的只是当前的工作树)子存储库,而不是历史记录)。如果您关心的子存储库中有本地历史记录,那么您应该在下面的第二个命令中删除子存储库的
.git
目录之前对其进行备份。 (另请考虑下面的 git 子树示例,它保留了子存储库 HEAD 的历史记录。这次添加目录时,不是子仓库,所以文件会正常添加。不幸的是,由于我们删除了 .git 目录,因此没有超级简单的方法可以使源存储库保持最新状态。
您可以考虑使用子树合并 相反。这样做可以让您轻松地从源存储库中提取更改,同时保持存储库中的文件“平坦”(无子模块)。第三方 git subtree 命令 是子树的一个很好的包装器合并功能。
稍后:
git 子树 还有一个
--squash
选项,可以让您避免将源存储库的历史记录合并到您的历史记录中,但仍然可以让您提取上游更改。You have added
vendor/plugins/open_flash_chart_2
as “gitlink” entry, but never defined it as a submodule. Effectively you are using the internal feature that git submodule uses (gitlink entries) but you are not using the submodule feature itself.You probably did something like this:
This last command is the problem. The directory
vendor/plugins/open_flash_chart_2
starts out as an independent Git repository. Usually such sub-repositories are ignored, but if you tell git add to explicitly add it, then it will create an gitlink entry that points to the sub-repository’s HEAD commit instead of adding the contents of the directory. It might be nice if git add would refuse to create such “semi-submodules”.Normal directories are represented as tree objects in Git; tree objects give names, and permissions to the objects they contain (usually other tree and blob objects—directories and files, respectively). Submodules are represented as “gitlink” entries; gitlink entries only contain the object name (hash) of the HEAD commit of the submodule. The “source repository” for a gitlink’s commit is specified in the
.gitmodules
file (and the.git/config
file once the submodule has been initialized).What you have is an entry that points to a particular commit, without recording the source repository for that commit. You can fix this by either making your gitlink into a proper submodule, or by removing the gitlink and replacing it with “normal” content (plain files and directories).
Turn It into a Proper Submodule
The only bit you are missing to properly define
vendor/plugins/open_flash_chart_2
as a submodule is a.gitmodules
file. Normally (if you had not already added it as bare gitlink entry), you would just usegit submodule add
:As you found, this will not work if the path already exists in the index. The solution is to temporarily remove the gitlink entry from the index and then add the submodule:
This will use your existing sub-repository (i.e. it will not re-clone the source repository) and stage a
.gitmodules
file that looks like this:It will also make a similar entry in your main repository’s
.git/config
(without thepath
setting).Commit that and you will have a proper submodule. When you clone the repository (or push to GitHub and clone from there), you should be able to re-initialize the submodule via
git submodule update --init
.Replace It with Plain Content
The next step assumes that your sub-repository in
vendor/plugins/open_flash_chart_2
does not have any local history that you want to preserve (i.e. all you care about is the current working tree of the sub-repository, not the history).If you have local history in the sub-repository that you care about, then you should backup the sub-repository’s
.git
directory before deleting it in the second command below. (Also consider the git subtree example below that preserves the history of the sub-repository’s HEAD).This time when adding the directory, it is not a sub-repository, so the files will be added normally. Unfortunately, since we deleted the
.git
directory there is no super-easy way to keep things up-to-date with the source repository.You might consider using a subtree merge instead. Doing so will let you easily pull in changes from the source repository while keeping the files “flat” in your repository (no submodules). The third-party git subtree command is a nice wrapper around the subtree merge functionality.
Later:
git subtree also has a
--squash
option that lets you avoid incorporating the source repository’s history into your history but still lets you pull in upstream changes.我刚刚遇到了同样的问题。原因是因为有一个子文件夹包含“.git”文件夹。删除它让 git 很高兴。
I just had the same problem. The reason was because there was a subfolder that contained a ".git" folder. Removing it made git happy.
参考 URL https://danielmiessler.com/blog/git-modified-未跟踪/#gs.W0C7X6U
Reference URL https://danielmiessler.com/blog/git-modified-untracked/#gs.W0C7X6U
指出我必须从 Chris Johansen 与 OP 的聊天中挖掘出的内容(从答案的回复中链接):
git addvendor/plugins/open_flash_chart_2
# will add gitlink, content will keep untrackedgit addvendor/plugins/open_flash_chart_2/
# 注意斜杠!!!!第二种形式将不使用gitlink添加它,并且内容是可跟踪的。 .git 目录很方便 &自动忽略。谢谢克里斯!
To point out what I had to dig out of Chris Johansen's chat with OP (linked from a reply to an answer):
git add vendor/plugins/open_flash_chart_2
# will add gitlink, content will stay untrackedgit add vendor/plugins/open_flash_chart_2/
# NOTICE THE SLASH!!!!The second form will add it without gitlink, and the contents are trackable. The .git dir is conveniently & automatically ignored. Thank you Chris!
我通过从子文件夹中删除 .git 文件解决了这个问题。
I solved this issue by deleting .git file from my subfolder.
我一直使用 Peter Lada 建议的技巧,称为“假子模块”:
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
它在几种情况下非常有用(pe我用它来保留我所有的存储库中的 Emacs 配置,包括 elpa/el-get 包目录内所有 git 存储库的当前 HEAD,因此当某些更新破坏某些内容时,我可以轻松回滚/前进到已知的工作版本)。
I use the trick suggested by Peter Lada all the time, dubbed as "fake submodules":
http://debuggable.com/posts/git-fake-submodules:4b563ee4-f3cc-4061-967e-0e48cbdd56cb
It's very useful in several scenarios (p.e. I use it to keep all my Emacs config in a repository, including the current HEAD of all git repositories inside the elpa/el-get package directories, so I could easily roll back/forward to a known working version when some update breaks something).
我在一个包含许多子模块的大项目中遇到了同样的问题。
基于 Chris Johnsen 此处和VonC 这里我构建了一个简短的 bash 脚本,它迭代所有现有的 gitlink 条目并将它们添加为适当的子模块。
这为我解决了它,我希望它有任何帮助。
I had the same problem with a big project with many submodules.
Based on the answers of Chris Johnsen here and VonC here I build a short bash script which iterates through all existing gitlink entries and adds them as proper submodules.
This fixed it for me, I hope it is of any help.
这对我来说效果很好:
git update-index --skip-worktree
如果它不适用于路径名,请尝试文件名。让我知道这是否也适合你。
再见!
This worked out just fine for me:
git update-index --skip-worktree
If it doesn't work with the pathname, try the filename. Let me know if this worked for you too.
Bye!
https://git-scm.com/book/en/v2/ Git-Tools-Submodules
我认为你应该阅读这篇文章来了解一些关于子模块的知识。写得很好,读起来并不需要花太多时间。
https://git-scm.com/book/en/v2/Git-Tools-Submodules
I think you should read this to learn a little about submodule. It's well-written, and it doesn't take much time to read it.
有同样的问题,但在这次讨论中没有解决。
我还遇到了线程开放中描述的子模块问题。
查看差异,我发现哈希值附加了一个 -dirty :
再次阅读文档,为我解决了问题。
http://web.mit.edu/jhawk /mnt/spo/git/git-doc/user-manual.html
查看“子模块的陷阱”部分
,原因是子模块内有更改或未跟踪的内容。
我首先必须进入子模块目录,执行“git add”+“git commit”以获取子模块中跟踪的所有内容。
现在,来自子模块的这个新 HEAD 可以提交给主模块。
Had the same problem, but it was not solved in this discussion.
I hit also the submodule problem as described in the thread opening.
Looking at the diff I recognized a -dirty appended to a hash:
Reading the docs again, solved the problem for me.
http://web.mit.edu/jhawk/mnt/spo/git/git-doc/user-manual.html
Look at section "Pitfalls with submodules"
Reason was, there were changes or untracked content within the submodule.
I first had to got to the submodule directory, do a "git add" + "git commit" to get all content tracked within the submodule.
Now this new HEAD from the submodule could be commited to the master module.
我最近在从事合同项目(视为机密)时遇到了这个问题。当然,出于安全目的,我必须运行代码的系统无法访问互联网,因此使用 Composer 和 npm 安装依赖项变得非常痛苦。
经过与我的同事深思熟虑后,我们决定直接复制粘贴我们的依赖项,而不是进行 Composer 安装或 npm 安装。
这导致我们不在 gitignore 中添加供应商和 npm_modules。这是我遇到这个问题的时候。
我用谷歌搜索了一下,发现了这个有用的线程。我对 Git 不是太专业,而且在工作时有点陶醉,我只是搜索了 sellers 文件夹中的所有子模块,
这给了我一些 4-5 个带有 git 的依赖项。我删除了所有这些 .git 文件夹,瞧,它成功了。
我知道这是一种黑客行为,而且无论如何也不是一种非常令人讨厌的行为。 SO诸神啊,请原谅我!下次我保证会阅读 gitlinks 并服从强大的 Linus Tovalds。
I recently encountered this problem while working on a contract project(deemed classified). The system in which I had to run the code did not have internet access, for security purposes of course, and so installing dependencies, using composer and npm, was becoming huge pain.
After much deliberation with my colleague, we decided to just wing it and copy paste our dependencies rather than doing composer install or npm install.
This led us to NOT add vendors and npm_modules in gitignore. This is when I encountered this problem.
I googled this a bit and found this helpful thread on SO. Not being too much of a pro in Git, and being a little intoxicated while working on it, I just searched for all the submodules in the vendors folder
This gave me some 4-5 dependencies that had git on them. I removed all these .git folders and voila, it worked.
I knows it's hack, and not a very geeky one anyways. O Gods of SO, please forgive me! Next time I promise to read up on gitlinks and obey O mighty Linus Tovalds.
这个问题已经得到解答,但我想我应该将收到这些消息时发现的内容添加到其中。
我有一个名为
playground
的存储库,其中包含许多沙盒应用程序。我通过克隆教程的存储库,将教程中的两个新应用程序添加到了 Playground 目录中。结果是新应用程序的 git 内容指向教程的存储库,而不是我的存储库。解决方案是从每个应用程序的目录中删除.git
目录,mv
将应用程序的目录放在playground
目录之外,然后mv
将它们返回并运行git add .
。之后就成功了。This question has been answered already, but thought I'd add to the mix what I found out when I got these messages.
I have a repo called
playground
that contains a number of sandbox apps. I added two new apps from a tutorial to theplayground
directory by cloning the tutorial's repo. The result was that the new apps' git stuff pointed to the tutorial's repo and not to my repo. The solution was to delete the.git
directory from each of those apps' directories,mv
the apps' directories outside theplayground
directory, and thenmv
them back and rungit add .
. After that it worked.首先转到目录:vendor/plugins/open_flash_chart_2和删除
然后:
输出
First go to the Directory : vendor/plugins/open_flash_chart_2 and DELETE
THEN :
OUTPUT
就我而言,应该添加有问题的模块,而路径中不带前导斜杠
/
。错误:
正确:
更改后以下命令解决了问题:
In my case the problematic module should have been added without leading slash
/
in the path.Wrong:
Correct:
After the change the following command resolved the issue:
唯一对我有用的方法是
git push
git add .
git commit -m "message"
code>git push
现在它可以工作了
Only thing that worked for me
.git
folder inside that sub-directorygit add .
git commit -m "cleaning up"
git push
git add .
git commit -m "message"
git push
Now it is working