如何摆脱 Git 子模块未跟踪状态?
我似乎无法摆脱 Git 子模块中未跟踪的内容。运行 git status 会产生:
# On branch master # Changes not staged for commit: # (use "git add ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # (commit or discard the untracked or modified content in submodules) # # modified: bundle/snipmate (untracked content) # modified: bundle/surround (untracked content) # modified: bundle/trailing-whitespace (untracked content) # modified: bundle/zencoding (untracked content) # no changes added to commit (use "git add" and/or "git commit -a")
添加 --ignore-submodules 参数会隐藏这些消息;但我想知道是否有一种方法可以以更合适、更核心的方式去除这些污垢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
我发现这个 博客文章 来整体工作。通过将
ignore = dirty
选项添加到.gitmodules
文件中的每个条目。I found this blog post to work overall. By adding the
ignore = dirty
option to each one of the entries in the.gitmodules
file.由于 git status 报告未跟踪的内容,因此获得干净状态的实际方法是进入每个子模块并:
.gitignore
具体到每个模块。.git/info/exclude
中,如 peci1 在评论中报告 /a>.或将 dirty 添加到子模块规范中,如 ezraspectre 的 答案(已投票)。
或添加一个全局
.gitignore
文件(通常为~/.gitignore-global
)。例如.DS_Store
或在我的例子中Carthage/Build
如 Marián Černý 在 评论。请参阅.gitginore
手册页:Since the git status reports untracked content, the actual way to have a clean status would be to go into each one of those submodules and:
.gitignore
specific to each module..git/info/exclude
, as peci1 reports in the comments.or add dirty to the submodule specification, as mentioned in ezraspectre's answer (upvoted).
or add a global
.gitignore
file (often~/.gitignore-global
). Like for example.DS_Store
or in my caseCarthage/Build
as reported by Marián Černý in the comments. See.gitginore
man page:您还可以转到每个子模块目录并充当单独的 git。
例如:
... /获取已修改文件的列表/
您还可以更新远程子模块存储库
毕竟
You can also go to each submodule dir and act as a separated git.
For example:
... /gets the list of modified files/
you can also update your remote submodule repo with
after all
这对我来说效果很好:
如果它不适用于
路径名
,请尝试使用文件名。让我知道这是否也适合你。
This worked out just fine for me:
If it doesn't work with the
pathname
, try the file name.Let me know if this worked for you too.
这可能是由于子模块分支中的
分离的 HEAD
造成的。如果是这种情况,请进入您的子模块路径(例如:./bundle/snipmate
),然后运行git checkout master
。It could be due to the
detached HEAD
in your submodule branch. If this is the case, go into your submodule path (e.g.:./bundle/snipmate
), then rungit checkout master
.当您有另一个 .git [隐藏文件夹] 时,可能会发生这种情况
在特定文件夹内..
修改:./../..(修改内容,未跟踪内容)
确保您的子目录不包含此 .git 文件夹。
如果是这种情况,可以通过从子目录中手动删除 .git 文件夹来解决问题。
This probably happens when you have another .git [hidden folder]
inside the particular folder..
modified: ./../.. (modified content, untracked content)
make sure your sub-directory does not contains this .git folder.
If That is the case the issue can be resolved by deleting the .git folder manually from the sub directory.
昨天我在一个有近 12 个子模块的项目中陷入了这个问题。
git status
显示输出。为了解决未跟踪的内容错误,我必须使用
*.pyc
、*.pyo
文件) >.gitignore。为了解决另一个问题,我必须运行 git submodule update 来更新每个子模块。
I got stuck on this issue yesterday, in a project which had close to 12 submodules.
git status
was showing output.To resolve the untracked content error, I had to remove the untracked files from all submodules (all were
*.pyc
,*.pyo
files generated by python) using a.gitignore
.To resolve the other, I had to run
git submodule update
which updated each of the submodules.在我的情况下,我克隆模块作为 ZF2 环境中新模块的起点。其作用是将其自己的 .git 文件夹放入该目录中。
这种情况下的解决方案是删除 .git 文件夹(您可能需要显示隐藏文件才能查看它)。
In my situation I clone modules as a starting point for a new module in my ZF2 environment. What this does is put its own .git folder into the directory.
Solution in this case is to delete the .git folder (you will likely need to show hidden files to view it).
我更喜欢使用 SourceTree,所以我的解决方案是打开 SourceTree 中的子模块存储库,它会显示列表所有未跟踪的文件。然后我将它们全部分组,然后使用“删除”。
我之所以能够做到这一点,是因为我知道所有未跟踪的文件实际上并不需要。
I prefer to use SourceTree, so the solution for me was to open the submodule repo in SourceTree which shows me list of all untracked files. I then group selected them all then used "Remove".
I was able to do this because I knew all the untracked files weren't actually needed.
如果这是临时问题,您可以进入子模块文件夹并运行 git reset HEAD --hard ,但您将丢失子模块内的所有更改。
If this is a temporary issue, you can go into the submodule folder and run
git reset HEAD --hard
but you will lose all your changes inside of the submodule.根据我的经验,对于 MacOS,可能会出现这种情况,因为创建了
._
文件:在这种情况下:尝试
dot_clean 。
In my experience, for MacOS, this can appear because
._
files were created:In that case: try
dot_clean .
只需删除子文件夹中的 .git 文件夹即可。
Just delete the .git folder in the subfolders.