如何摆脱 Git 子模块未跟踪状态?

发布于 2024-10-19 05:57:24 字数 682 浏览 2 评论 0 原文

我似乎无法摆脱 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 参数会隐藏这些消息;但我想知道是否有一种方法可以以更合适、更核心的方式去除这些污垢。

I can't seem to get rid of untracked content in Git's submodules. Running git status yields:

# 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")

Adding the --ignore-submodules parameter hides these messages; but I wonder if there's a way to get rid of this dirt in a more suitable, core-ish, manner.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

蓝咒 2024-10-26 05:57:24

我发现这个 博客文章 来整体工作。通过将 ignore = dirty 选项添加到 .gitmodules 文件中的每个条目。

[submodule "zen-coding-gedit3"]
    path = zen-coding-gedit3
    url = git://github.com/leafac/zen-coding-gedit3.git
    ignore = dirty

I found this blog post to work overall. By adding the ignore = dirty option to each one of the entries in the .gitmodules file.

[submodule "zen-coding-gedit3"]
    path = zen-coding-gedit3
    url = git://github.com/leafac/zen-coding-gedit3.git
    ignore = dirty
娇妻 2024-10-26 05:57:24

由于 git status 报告未跟踪的内容,因此获得干净状态的实际方法是进入每个子模块并:

  • 添加并提交未跟踪的内容,
  • 或在 .gitignore 具体到每个模块。
  • 或者您可以将相同的忽略内容添加到子模块的 .git/info/exclude 中,如 peci1 在评论中报告 /a>.
  • 或将 dirty 添加到子模块规范中,如 ezraspectre答案(已投票)。

    git config -f .gitmodules submodule..ignore untracked
    
  • 或添加一个全局 .gitignore 文件(通常为~/.gitignore-global)。例如 .DS_Store 或在我的例子中 Carthage/BuildMarián Černý评论。请参阅 .gitginore 手册页

用户希望 Git 在所有情况下都忽略的模式(例如,由用户选择的编辑器生成的备份或临时文件)通常会进入由 core.excludesFile 指定的文件< /strong> 在用户的 ~/.gitconfig 中。它的默认值为 $XDG_CONFIG_HOME/git/ignore。如果 $XDG_CONFIG_HOME 未设置或为空,则使用 $HOME/.config/git/ignore


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:

  • add and commit the untracked contents,
  • or reference the untracked contents in a .gitignore specific to each module.
  • or you can add the same ignored content to the submodule's .git/info/exclude, as peci1 reports in the comments.
  • or add dirty to the submodule specification, as mentioned in ezraspectre's answer (upvoted).

    git config -f .gitmodules submodule.<path>.ignore untracked
    
  • or add a global .gitignore file (often ~/.gitignore-global). Like for example .DS_Store or in my case Carthage/Build as reported by Marián Černý in the comments. See .gitginore man page:

Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.

旧人哭 2024-10-26 05:57:24

您还可以转到每个子模块目录并充当单独的 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

毕竟

You can also go to each submodule dir and act as a separated git.
For example:

cd my/project/submodule
git status

... /gets the list of modified files/

git add .  //to add all of them to commit into submodule
git commit -m "message to your submodule repo"

you can also update your remote submodule repo with

git submodule update

after all

看轻我的陪伴 2024-10-26 05:57:24

这对我来说效果很好:

git update-index --skip-worktree <path>

如果它不适用于路径名,请尝试使用文件名。
让我知道这是否也适合你。

This worked out just fine for me:

git update-index --skip-worktree <path>

If it doesn't work with the pathname, try the file name.
Let me know if this worked for you too.

二货你真萌 2024-10-26 05:57:24

这可能是由于子模块分支中的分离的 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.

初雪 2024-10-26 05:57:24

当您有另一个 .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.

忱杏 2024-10-26 05:57:24

昨天我在一个有近 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 来更新每个子模块。

I got stuck on this issue yesterday, in a project which had close to 12 submodules.

git status was showing output.

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

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.

北城半夏 2024-10-26 05:57:24

在我的情况下,我克隆模块作为 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).

国产ˉ祖宗 2024-10-26 05:57:24

我更喜欢使用 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.

在梵高的星空下 2024-10-26 05:57:24

如果这是临时问题,您可以进入子模块文件夹并运行 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.

空城仅有旧梦在 2024-10-26 05:57:24

根据我的经验,对于 MacOS,可能会出现这种情况,因为创建了 ._ 文件:
在这种情况下:尝试 dot_clean 。

In my experience, for MacOS, this can appear because ._ files were created:
In that case: try dot_clean .

垂暮老矣 2024-10-26 05:57:24

只需删除子文件夹中的 .git 文件夹即可。

Just delete the .git folder in the subfolders.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文