具有修改和未跟踪内容的git子模块 - 为什么以及如何删除它?

时间:2011-11-03 10:34:46

标签: git

这就是我的git status'结果:

# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   vim/bundle/pathogen (modified content)
#   modified:   vim/bundle/sparkup (untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

正在运行git diff vim会显示:

diff --git a/vim/bundle/pathogen b/vim/bundle/pathogen
--- a/vim/bundle/pathogen
+++ b/vim/bundle/pathogen
@@ -1 +1 @@
-Subproject commit fcf77f5101f3e589ce006c40ad3a0432735a05cf
+Subproject commit fcf77f5101f3e589ce006c40ad3a0432735a05cf-dirty
diff --git a/vim/bundle/sparkup b/vim/bundle/sparkup
--- a/vim/bundle/sparkup
+++ b/vim/bundle/sparkup
@@ -1 +1 @@
-Subproject commit 04a81b41f116a19184359a6f8685c192f5c36c70
+Subproject commit 04a81b41f116a19184359a6f8685c192f5c36c70-dirty

为什么一个未跟踪,另一个修改,差异是什么意思?但最重要的是:它是如何发生的以及如何摆脱它?

6 个答案:

答案 0 :(得分:53)

vim/bundle/pathogen中的一个跟踪文件已被修改。子模块vim/bundle/sparkup中还有一些未跟踪(和未标记)的内容。在任何一种情况下,找出修改/未修改内容的方法是更改​​到子模块目录并运行git status。 (对于子模块中未跟踪的文件,这通常是尚未在上游添加到.gitignore的构建产品。)

答案 1 :(得分:43)

ignore = dirty添加到位于repo根目录的submodule个文件中的每个有问题的.gitmodules部分。例如:

[submodule "vim/bundle/nerdtree"]                                               
  path = vim/bundle/nerdtree                                                    
  url = https://github.com/scrooloose/nerdtree.git                              
  ignore = dirty

如在NilsH的How to ignore changes in git submodules所见。感谢Synchronizing plugins with git submodules and pathogen vimcast。

答案 2 :(得分:24)

进入子模块的目录并确保没有任何内容(某种输出)没有你知道。

cd submoduledir/
git status

如果您在此处看到任何未跟踪的文件,请执行此操作以删除它们:

git reset --hard HEAD
git clean -fxd

答案 3 :(得分:4)

如果你真的确定要这样做(我正在管理带有病原体和git子模块的vim包以及一些我如何在repos中获得一些标签文件夹 - 他们只需要去)你可以循环通过子模块删除未跟踪的文件。

cd YOUR_REPO_WITH_SUBMODULES/
git submodule foreach git clean -f -d

-f强制,-d删除目录

您可以在此处查看文档:{​​{3}}

答案 4 :(得分:2)

我遇到了同样的情况:

  

gongzelong:shadowsocks-android gongzelong $ git status在分支主机上   您的分支机构的最新信息是“来源/主”。

     

未进行提交的更改:(使用“ git add ...”进行更新   将提交的内容)(使用“ git checkout-...”丢弃   工作目录中的更改)(提交或丢弃未跟踪的或   修改了子模块中的内容)

    modified:   core/src/main/jni/badvpn (modified content)
    modified:   core/src/main/jni/libancillary (modified content)
    modified:   core/src/main/jni/libevent (modified content)
    modified:   core/src/main/jni/redsocks (modified content)
    modified:   core/src/overture/src/github.com/shadowsocks/overture (modified
     

内容)

     

未添加任何更改来提交(使用“ git add”和/或“ git commit -a”)

当我git diff看到什么变化时:

gongzelong:shadowsocks-android gongzelong$ git diff
diff --git a/core/src/main/jni/badvpn b/core/src/main/jni/badvpn
--- a/core/src/main/jni/badvpn
+++ b/core/src/main/jni/badvpn
@@ -1 +1 @@
-Subproject commit 58f8a8883e51e5cb97391c4b6733ce255bf11f95
+Subproject commit 58f8a8883e51e5cb97391c4b6733ce255bf11f95-dirty
diff --git a/core/src/main/jni/libancillary b/core/src/main/jni/libancillary
--- a/core/src/main/jni/libancillary
+++ b/core/src/main/jni/libancillary
@@ -1 +1 @@
-Subproject commit 311e5d14f593f16c785bc6605220517eb1f21f6b
+Subproject commit 311e5d14f593f16c785bc6605220517eb1f21f6b-dirty
diff --git a/core/src/main/jni/libevent b/core/src/main/jni/libevent
--- a/core/src/main/jni/libevent
+++ b/core/src/main/jni/libevent
@@ -1 +1 @@
-Subproject commit f29f07bc8c43eec96f227e6f6eede32b3af66168
+Subproject commit f29f07bc8c43eec96f227e6f6eede32b3af66168-dirty
diff --git a/core/src/main/jni/redsocks b/core/src/main/jni/redsocks
--- a/core/src/main/jni/redsocks
+++ b/core/src/main/jni/redsocks
@@ -1 +1 @@
-Subproject commit 274334f14839431ae003774d99c3d1de337afff4
+Subproject commit 274334f14839431ae003774d99c3d1de337afff4-dirty
diff --git a/core/src/overture/src/github.com/shadowsocks/overture b/core/src/overture/src/github.com/shadowsocks/overture
--- a/core/src/overture/src/github.com/shadowsocks/overture
+++ b/core/src/overture/src/github.com/shadowsocks/overture
@@ -1 +1 @@
-Subproject commit a9b5a94e215c1beadfe11442994b550e1e81f8d6
+Subproject commit a9b5a94e215c1beadfe11442994b550e1e81f8d6-dirty

我这样修复:

  

gongzelong:shadowsocks-android gongzelong $ git子模块更新--init   gongzelong:shadowsocks-android gongzelong $ git子模块,每个git   reset --hard输入'core / src / main / jni / badvpn'

     

HEAD现在位于58f8a88,修正了UDP校验和计算错误。进入   'core / src / main / jni / libancillary'HEAD现在位于311e5d1 Fix C ++   HEAD现在位于5213419,输入“ core / src / main / jni / libev”   合并来自Mygod / master的拉取请求#2进入   'core / src / main / jni / libevent'HEAD现在位于f29f07bc更新至2.1.8   输入``core / src / main / jni / libsodium''的HEAD现在位于c5e43f4c更新   dotnet示例版本输入“ core / src / main / jni / mbedtls” HEAD为   现在位于4f0929189,将版本号更新为2.6.1。   'core / src / main / jni / pcre'HEAD现在位于222bbf4合并“ pcre:无声   无趣的警告。”上午:0e44fd55f8进入   'core / src / main / jni / redsocks'HEAD现在位于274334f使用标准    ANDROID 预处理程序宏(#1)输入'core / src / main / jni / shadowsocks-libev'HEAD现在位于57e74ea。修复了一个错误   在绕过进入   'core / src / overture / src / github.com / shadowsocks / overture'HEAD现在位于   a9b5a94格式化源代码gongzelong:shadowsocks-android   gongzelong $ gongzelong:shadowsocks-android gongzelong $ git status开启   分支主管您的分支是最新的'origin / master'。

     

什么也没提交,工作树很干净

参考:git-discard-submodule-changes

答案 5 :(得分:1)

作为FAQ中病原体的作者,您可以全局忽略标记:

git config --global core.excludesfile '~/.cvsignore'
echo tags >> ~/.cvsignore