我似乎无法摆脱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
参数会隐藏这些消息;但我想知道是否有办法以更合适的核心方式摆脱这种污垢。
答案 0 :(得分:131)
我发现这个blog post可以全面运作。通过向ignore = dirty
文件中的每个条目添加.gitmodules
选项。
[submodule "zen-coding-gedit3"]
path = zen-coding-gedit3
url = git://github.com/leafac/zen-coding-gedit3.git
ignore = dirty
答案 1 :(得分:81)
由于git状态报告未跟踪的内容,因此获得干净状态的实际方法是进入每个子模块,并且:
.gitignore
中未跟踪的内容。 .git/info/exclude
,而peci1报告in the comments。或将脏添加到子模块规范中,如ezraspectre的answer {upvoted)中所述。
git config -f .gitmodules submodule.<path>.ignore untracked
或添加全局 .gitignore
文件(通常为~/.gitignore-global
)。例如,Marián Černý中the comments报告的.DS_Store
或我的Carthage/Build
{}}。见.gitginore
man page:
用户希望Git在所有情况下忽略的模式(例如,由用户选择的编辑器生成的备份或临时文件)通常会进入由
core.excludesFile
指定的文件中。用户的~/.gitconfig
。其默认值为$XDG_CONFIG_HOME/git/ignore
。如果$XDG_CONFIG_HOME
未设置或为空,则会使用$HOME/.config/git/ignore
。
答案 2 :(得分:10)
您也可以转到每个子模块目录并充当分离的git。 例如:
cd my/project/submodule
git status
... / 获取已修改文件的列表 /
git add . //to add all of them to commit into submodule
git commit -m "message to your submodule repo"
您还可以使用
更新远程子模块库git submodule update
毕竟
答案 3 :(得分:3)
这可能是由于子模块分支中的detached HEAD
。进入子模块路径(例如:./bundle/snipmate
),然后进入git checkout master
。
我希望这会有所帮助:)
答案 4 :(得分:1)
我昨天在一个有近12个子模块的项目中遇到了这个问题。
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: proj1 (untracked content)
# modified: proj1 (modified content, untracked content)
# ...
要解决未跟踪的内容错误,我必须使用*.pyc
从所有子模块(所有子文件都是*.pyo
,.gitignore
文件)中删除未跟踪的文件。
要解决另一个问题,我必须运行更新每个子模块的git submodule update
。
答案 5 :(得分:0)
在我的情况下,我将模块克隆为ZF2环境中新模块的起点。这样做是将自己的.git文件夹放入目录中。
在这种情况下,解决方法是删除.git文件夹(您可能需要显示隐藏文件才能查看)。
答案 6 :(得分:0)
这对我来说很好:
git update-index --skip-worktree
如果它不适用于路径名,请尝试使用文件名。 让我知道这是否对您也有用。
再见!
答案 7 :(得分:0)
当您有另一个.git [隐藏文件夹]时,可能会发生这种情况 在特定文件夹中。
修改后:./../ ..(修改后的内容,未跟踪的内容)
确保您的子目录不包含此.git文件夹。
如果是这种情况,可以通过从子目录中手动删除.git文件夹来解决此问题。
答案 8 :(得分:0)
我更喜欢使用SourceTree,所以对我来说,解决方案是在SourceTree中打开子模块存储库,该树向我显示所有未跟踪文件的列表。然后,我将所有对象分组,然后使用“删除”。
之所以能够做到这一点,是因为我知道实际上并不需要所有未跟踪的文件。
答案 9 :(得分:0)
根据我的经验,对于 MacOS,这可能是因为创建了 ._
文件:
在这种情况下:尝试 dot_clean .
答案 10 :(得分:-1)
如果这是一个临时问题,您可以进入子模块文件夹并运行git reset HEAD --hard
,但您将丢失子模块内的所有更改。