带有修改和未跟踪内容的 git 子模块 - 为什么以及如何删除它?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7993413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git submodules with modified and untracked content - why and how to remove it?
提问by Nils Riedemann
this is what my git status
' result looks like:
这就是我的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")
running git diff vim
shows this:
运行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
Why is the one untracked, the other modified, what does the diff mean? But most important: how did it happen and how to get rid of it?
为什么一个未跟踪,另一个修改,差异是什么意思?但最重要的是:它是如何发生的以及如何摆脱它?
回答by Mark Longair
One of the tracked files in vim/bundle/pathogen
has been modified somehow. There is also some untracked (and unignored) content in the submodule vim/bundle/sparkup
. In either case, the way to figure out what is modified / untracked is to change into the submodule directory and run git status
. (In the case of untracked files in a submodule, this is frequently a build product that has not been added to .gitignore
in upstream.)
中的其中一个跟踪文件vim/bundle/pathogen
已以某种方式进行了修改。子模块中还有一些未跟踪(和未忽略)的内容vim/bundle/sparkup
。在任何一种情况下,找出修改/未跟踪内容的方法是更改到子模块目录并运行git status
. (对于子模块中未跟踪的文件,这通常是未添加到.gitignore
上游的构建产品。)
回答by ciastek
Add ignore = dirty
to each problematic submodule
section in .gitmodules
files placed at root of repo. Example:
添加ignore = dirty
到位于 repo 根目录的文件中的每个有问题的submodule
部分.gitmodules
。例子:
[submodule "vim/bundle/nerdtree"]
path = vim/bundle/nerdtree
url = https://github.com/scrooloose/nerdtree.git
ignore = dirty
As seen at NilsH's How to ignore changes in git submodules. Found thanks to Synchronizing plugins with git submodules and pathogenvimcast.
如 NilsH 的How to ignore changes in git submodules所见。感谢使用 git 子模块和病原体vimcast同步插件。
回答by Maurizio
Head into the submodule's directory and make sure there isn't anything being built (an output of some kind) w/o you knowing.
进入子模块的目录并确保没有你知道的任何东西被构建(某种输出)。
cd submoduledir/
git status
If you see any untracked files in here, just do this to remove them:
如果您在这里看到任何未跟踪的文件,只需执行以下操作即可将其删除:
git reset --hard HEAD
git clean -fxd
回答by Francis Bacon
I encountered the same situation:
我遇到了同样的情况:
gongzelong:shadowsocks-android gongzelong$ git status On branch master Your branch is up to date with 'origin/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: 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
content)
no changes added to commit (use "git add" and/or "git commit -a")
gogzelong:shadowsocks-android gogzelong$ git status 在分支 master 你的分支是最新的'origin/master'。
未为提交暂存的更改:(使用“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”)
When I git diff to see what is the changes:
当我 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
I fixed it like this:
我是这样修复的:
gongzelong:shadowsocks-android gongzelong$ git submodule update --init gongzelong:shadowsocks-android gongzelong$ git submodule foreach git reset --hard Entering 'core/src/main/jni/badvpn'
HEAD is now at 58f8a88 Fix bug UDP checksum calculation. Entering 'core/src/main/jni/libancillary' HEAD is now at 311e5d1 Fix C++ building Entering 'core/src/main/jni/libev' HEAD is now at 5213419 Merge pull request #2 from Mygod/master Entering 'core/src/main/jni/libevent' HEAD is now at f29f07bc Update to 2.1.8 Entering 'core/src/main/jni/libsodium' HEAD is now at c5e43f4c Update dotnet example version Entering 'core/src/main/jni/mbedtls' HEAD is now at 4f0929189 Update version number to 2.6.1 Entering 'core/src/main/jni/pcre' HEAD is now at 222bbf4 Merge "pcre: silence uninteresting warnings." am: 0e44fd55f8 Entering 'core/src/main/jni/redsocks' HEAD is now at 274334f Use standard ANDROIDpreprocessor macro (#1) Entering 'core/src/main/jni/shadowsocks-libev' HEAD is now at 57e74ea Fix a bug in bypassing Entering 'core/src/overture/src/github.com/shadowsocks/overture' HEAD is now at a9b5a94 Format the source code gongzelong:shadowsocks-android gongzelong$ gongzelong:shadowsocks-android gongzelong$ git status On branch master Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
gogzelong:shadowsocks-android gogzelong$ git submodule update --init gogzelong:shadowsocks-android gogzelong$ git submodule foreach git reset --hard 进入'core/src/main/jni/badvpn'
HEAD 现在位于 58f8a88 修复错误 UDP 校验和计算。进入'core/src/main/jni/libancillary' HEAD 现在在 311e5d1 Fix C++ building 进入'core/src/main/jni/libev' HEAD 现在在 5213419 Merge pull request #2 from Mygod/master Entering '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:沉默无趣的警告”。am: 0e44fd55f8 Entering '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 格式化源代码 gogzelong:shadowsocks-android gongzelong$ gogzelong:shadowsocks-android gogzelong$ git status 在分支 master 你的分支是最新的'origin/master'。
没有什么可提交的,工作树干净
Reference: git-discard-submodule-changes
回答by bloke_zero
If you're really sure you want to just do it (I'm managing vim bundles with pathogen and git submodules and some how I managed to get some tags folders in repos - and they just had to go) you can loop through submodules and remove untracked files.
如果你真的确定你只想这样做(我正在管理带有病原体和 git 子模块的 vim 包,以及我如何设法在 repos 中获取一些标签文件夹 - 他们只是不得不去)你可以循环遍历子模块和删除未跟踪的文件。
cd YOUR_REPO_WITH_SUBMODULES/
git submodule foreach git clean -f -d
-f
to force, -d
to remove directories
-f
强制,-d
删除目录
You can check the docs here: https://git-scm.com/docs/git-clean
您可以在此处查看文档:https: //git-scm.com/docs/git-clean