如何追踪未追踪的内容? [英] How to track untracked content?

查看:174
本文介绍了如何追踪未追踪的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅下面的实线。我的原始问题。



我的本​​地目录中有一个未追踪的文件夹。当我运行 git status 时,我得到:

 已更改但未更新:
修改:vendor / plugins / open_flash_chart_2(修改内容,未跟踪内容)

键入 git add vendor / plugins / open_flash_chart_2 然后再次尝试 git status ,它仍然表示未跟踪。这是怎么回事?






以下是我最近半小时的简单汇总:


  • 发现我的Github repo没有跟踪我的 vendor / plugins / open_flash_chart_2 插件。具体而言,没有内容,它在文件夹图标上显示绿色箭头

  • init

     在路径'vendor / plugins / open_flash_chart_2'中找不到在.gitmodules中找到的子模块映射


  • 试过 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已存在于索引


  • git status

     修改:vendor / plugins / open_flash_chart_2(未跟踪内容)


  • 在我的资源库/本地目录中找到任何名为 .gitmodules 的文件,但找不到它。




我需要做些什么才能使我的子模块正常工作,以便git可以正确开始跟踪 p>




这可能不起作用ated(我包含它以防万一),但每次我输入 git commit -a 而不是我通常的 git commit -m我的评论,它会抛出一个错误:

  E325:注意
找到交换文件名称为.git\.COMMIT-EDITMSG.swp
日期:Thu Nov 11 19:45:05 2010
文件名:c:/san/project/.git/COMMIT_EDITMSG
修改:是
用户名:San主机名称:San-PC
进程ID:4268
打开文件.git\COMMIT_EDITMSG
日期:Thu Nov 11 20:56:09 2010
比交换文件更新!
交换文件.git\.COMMIT_EDITMSG.swp已经存在!
[O] pen只读,(E)Dit无论如何,(R)ecover,(D)elete它,(Q)uit,(A)bort:
交换文件.git \ .COMMIT_EDITMSG.swp已经存在!
[O] pen只读,(E)Dit无论如何,(R)ecover,(D)elete它,(Q)Uit,(A)bort:

我是Github的一名完全新手,尽管试图通过文档,但我对这些特殊问题感到困惑。谢谢。

解决方案

您已将供应商/插件/ open_flash_chart_2 添加为gitlink条目,但从未将其定义为子模块。实际上,您正在使用 git submodule 使用的内部功能(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 拒绝创建这样的半子模块,它可能会很好。


$ b 普通目录在Git中表示为树对象;树对象为它们包含的对象提供名称和权限(通常分别为其他树和blob对象 - 目录和文件)。子模块被表示为gitlink条目; gitlink条目只包含子模块HEAD提交的对象名称(哈希)。 gitlink提交的源代码库在 .gitmodules 文件(和 .git / config 文件)中指定一旦子模块被初始化)。

你有一个指向特定提交的条目,而不记录该提交的源存储库。你可以通过将你的gitlink变成一个合适的子模块来解决这个问题,或者通过移除gitlink并用普通内容(普通文件和目录)替换它。

Turn它变成了一个合适的子模块



您仅仅将 vendor / plugins / open_flash_chart_2 定义为子模块是 .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 文件:
$ b

  [submodulevendor / 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 (没有路径设置)中做类似的条目。



承诺,你将有一个合适的子模块。当你克隆版本库(或者推送到GitHub并从那里克隆)时,你应该可以通过 git submodule update --init 来重新初始化子模块。



将其替换为纯文本内容



下一步假设您的子存储库位于 vendor / plugins / open_flash_chart_2 没有任何你想保留的本地历史记录(即你所关心的只是子库的当前工作树,而不是历史记录)。



如果您在您关心的子存储库中有本地历史记录,那么您应该备份子存储库的 .git 目录然后在下面的第二个命令中删除它。(同时考虑下面的子树示例,该示例保留子存储库HEAD的历史记录。)

  git rm  - 缓存供应商/插件/ open_flash_chart_2 
rm -rf供应商/插件/ open_flash_chart_2 / .git#返回首页除非您确定您有没有本地变化
git add vendor / plugins / open_flash_chart_2

这次添加该目录,它不是一个子库,所以文件将被正常添加。不幸的是,由于我们删除了 .git 目录,因此没有超级简单的方法可以使源代码库保持最新。



您可以考虑使用子树合并。这样做可以让您轻松地从源存储库中引入更改,同时将文件保留在存储库中(无子模块)。第三方 git subtree 命令是围绕子树的一个很好的包装合并功能。

  git rm  - 缓存vendor / plugins / open_flash_chart_2 
git commit -m转换为子树;请支持'
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#如果HEAD是本地历史的唯一提示

稍后:

  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 subtree 也有一个 - squash 选项,可以让你避免将源代码库的历史记录合并到历史记录中,但仍然可以引入上游更改。

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.

解决方案

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:

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

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 use git submodule add:

git submodule add git://github.com/korin/open_flash_chart_2_plugin.git vendor/plugins/open_flash_chart_2

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:

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

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:

[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

It will also make a similar entry in your main repository’s .git/config (without the path 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).

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

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.

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

Later:

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 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.

这篇关于如何追踪未追踪的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆