- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我更新一个父项目分支中的子模块,然后切换到同一工作树中的另一个分支,则子模块引用看起来好像已被修改。
例如(哈希值可能会有所不同,您可能必须向下滚动代码窗 Eloquent 能看到所有行):
# create soon to be submodule
mkdir /tmp/example-submodule
cd /tmp/example-submodule
git init
echo a > a
git add a
git commit -m 'm'
cp -r .git /tmp/example-submodule.git
cd /tmp/example-submodule.git
git config --bool core.bare true
cd /tmp
/bin/rm -rf /tmp/example-submodule
git clone file:///tmp/example-submodule.git
#create other project and add sub-module
mkdir /tmp/example-supermodule
cd /tmp/example-supermodule
git init
echo x > x
git add x
git commit -m 'm'
cp -r .git /tmp/example-supermodule.git
cd /tmp/example-supermodule.git
git config --bool core.bare true
cd /tmp
/bin/rm -rf /tmp/example-supermodule
git clone file:///tmp/example-supermodule.git
#update the submodule
cd /tmp/example-supermodule
git submodule add file:///tmp/example-submodule.git example-sub
git commit -a -m'm'
git submodule status
# prints: 189ea25d45618862d0bfcbf5bd995e05ce1c2e4e example-sub (heads/master)
git push
#update the submodule
cd /tmp/example-submodule
echo b > b
git add b
git commit -m 'm'
git push
#create new branch in super module and update submodule to new HEAD
cd /tmp/example-supermodule
git branch otherbranch
git checkout otherbranch
git submodule update --remote
git commit -a -m'm'
git submodule status
# prints: 26f94e59002603475a1ba731104f92e10e88cf6b example-sub (remotes/origin/HEAD)
git push origin otherbranch
#checkout another branch
git checkout master
git status
cat .git/modules/example-sub/HEAD
# prints: 26f94e59002603475a1ba731104f92e10e88cf6b
master check out 后,子模块的hash不同,好像其他分支的更新也影响了master。
如果我克隆 super 项目而不是在同一个工作树中切换分支:
cd /tmp
git clone --recursive file:///tmp/example-supermodule.git/ other
cd /tmp/other
git submodule status
它显示了在 master 分支中添加的子模块提交。
某人如何在他们的工作树中的分支之间切换并使子模块的提交与提交的内容相匹配?或者如何在更改分支后恢复显示子模块在该分支中未修改时已修改?
最佳答案
我刚刚用 git 2.9.0 重现了这个问题
最后你需要做的就是找回干净的主人:
git submodule update
这会将子模块重置为其 master
值,并且 .git/modules/example-sub/HEAD
将具有正确的值
当你再次 checkout 时,你会遇到同样的问题otherbranch
。
右边<强>gitlink ( special entry in the index ) 将被 checkout 。
但是 .git/modules/example-sub/HEAD
不会立即更改。
在这两种情况下,那是因为 checkout 只修改 gitlink,不子模块的内容。
只有 git submodule update
会实际将子模块的内容 check out 到其记录的 gitlink SHA1。
这样一来,如果您在子模块中有正在进行的工作,它们就不会被父仓库中的 check out 清除。
这是我自己的实验:
C:\Users\vonc\prog\git\tests>mkdir subm
C:\Users\vonc\prog\git\tests>cd subm
让我们创建两个存储库,每个存储库有一个提交:
C:\Users\vonc\prog\git\tests\subm>git init s
Initialized empty Git repository in C:/Users/vonc/prog/git/tests/subm/s/.git/
C:\Users\vonc\prog\git\tests\subm>git init p
Initialized empty Git repository in C:/Users/vonc/prog/git/tests/subm/p/.git/
C:\Users\vonc\prog\git\tests\subm>cd s
C:\Users\vonc\prog\git\tests\subm\s>git commit --allow-empty -m "first s commit"
[master (root-commit) d11bd81] first s commit
C:\Users\vonc\prog\git\tests\subm\s>cd ..\p
C:\Users\vonc\prog\git\tests\subm\p>git commit --allow-empty -m "first p commit"
[master (root-commit) 10a7044] first p commit
让我们添加 s
作为 p
(父仓库)的子模块
C:\Users\vonc\prog\git\tests\subm\p>git submodule add -- ../s
Cloning into 'C:/Users/vonc/prog/git/tests/subm/p/s'...
done.
C:\Users\vonc\prog\git\tests\subm\p>git st
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitmodules
new file: s
C:\Users\vonc\prog\git\tests\subm\p>git commit -m "add p"
[master aa33ba9] add p
2 files changed, 4 insertions(+)
create mode 100644 .gitmodules
create mode 160000 s
现在让我们修改 s
仓库,添加一个新的提交到它的 master
分支
C:\Users\vonc\prog\git\tests\subm\p>cd ..\s
C:\Users\vonc\prog\git\tests\subm\s>git commit --allow-empty -m "second s commit"
[master 81e4800] second s commit
C:\Users\vonc\prog\git\tests\subm\s>gl
* 81e4800 - (HEAD -> master) second s commit (1 second ago) <VonC>
* d11bd81 - first s commit (3 minutes ago) <VonC>
让我们在父仓库中创建一个新分支
C:\Users\vonc\prog\git\tests\subm\s>cd ..\p
C:\Users\vonc\prog\git\tests\subm\p>git commit --allow-empty -m "second s commit"
C:\Users\vonc\prog\git\tests\subm\p>git checkout -b branch
Switched to a new branch 'branch'
让我们更新子模块,并将其添加到新分支branch
:
C:\Users\vonc\prog\git\tests\subm\p>git submodule update --remote
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From C:/Users/vonc/prog/git/tests/subm/s
d11bd81..81e4800 master -> origin/master
Submodule path 's': checked out '81e48007afc90aceca16d884d0fdc34074121732'
C:\Users\vonc\prog\git\tests\subm\p>git st
On branch branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: s (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
C:\Users\vonc\prog\git\tests\subm\p>git add .
C:\Users\vonc\prog\git\tests\subm\p>git commit -m "update s to latest master"
[branch 271a4fb] update s to latest master
1 file changed, 1 insertion(+), 1 deletion(-)
C:\Users\vonc\prog\git\tests\subm\p>cat .git\modules\s\HEAD
81e48007afc90aceca16d884d0fdc34074121732
C:\Users\vonc\prog\git\tests\subm\p>gl
* 271a4fb - (HEAD -> branch) update s to latest master (26 seconds ago) <VonC>
* f86aab2 - (master) second s commit (2 minutes ago) <VonC>
* aa33ba9 - add p (3 minutes ago) <VonC>
* 10a7044 - first p commit (4 minutes ago) <VonC>
我 check out master
, check out 正确的子模块SHA1,但是子模块的内容还没有改变。
C:\Users\vonc\prog\git\tests\subm\p>git checkout master
M s
Switched to branch 'master'
C:\Users\vonc\prog\git\tests\subm\p>cat .git\modules\s\HEAD
81e48007afc90aceca16d884d0fdc34074121732
C:\Users\vonc\prog\git\tests\subm\p>git st
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: s (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
如果我切换回分支 branch
,状态将是干净的(那是因为子模块 s
的内容与其记录的 gitlink SHA1 匹配)
C:\Users\vonc\prog\git\tests\subm\p>git checkout branch
Switched to branch 'branch'
C:\Users\vonc\prog\git\tests\subm\p>git st
On branch branch
nothing to commit, working directory clean
但是在 master
上,我需要一个 submodule update
来将子模块 s
的内容重置为它的 SHA1:
C:\Users\vonc\prog\git\tests\subm\p>git checkout master
M s
Switched to branch 'master'
C:\Users\vonc\prog\git\tests\subm\p>git submodule update
Submodule path 's': checked out 'd11bd8132971a18e3e7cd19984cc6ce106478087'
C:\Users\vonc\prog\git\tests\subm\p>cat .git\modules\s\HEAD
d11bd8132971a18e3e7cd19984cc6ce106478087
C:\Users\vonc\prog\git\tests\subm\p>git st
On branch master
nothing to commit, working directory clean
当我 checkout branch
时会出现同样的问题:
C:\Users\vonc\prog\git\tests\subm\p>
C:\Users\vonc\prog\git\tests\subm\p>git checkout branch
M s
Switched to branch 'branch'
C:\Users\vonc\prog\git\tests\subm\p>git st
On branch branch
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: s (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
C:\Users\vonc\prog\git\tests\subm\p>git show s
commit 271a4fb6bf79e2524f98dfbd505b2876b0c173a8
Author: VonC <vonc@laposte.net>
Date: Sat Jul 9 06:52:57 2016 +0200
update s to latest master
diff --git a/s b/s
index d11bd81..81e4800 160000
--- a/s
+++ b/s
@@ -1 +1 @@
-Subproject commit d11bd8132971a18e3e7cd19984cc6ce106478087
+Subproject commit 81e48007afc90aceca16d884d0fdc34074121732
同样,git submodule update
会将子模块 s
的内容重置为记录在父存储库的分支 branch
中的 SHA1。
关于git - 如何将 git 子模块恢复到它的提交版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38276448/
有什么方法可以恢复删除的元素吗? 这是我删除元素的代码 myFunction() { var width = window.innerWidth; var February = doc
我有一个 TokuDB 表,由于某种原因缺少 ***_status.tokudb 文件。 我还不确定文件是否由于 TokuDB 崩溃而丢失。 问题是: 有没有办法从主要文件和关键文件(我可以从 tok
我正在 Windows 7 (x86) 上运行带有 Workbench 6.3.8 的 32 位 MySQL Server 5.7.22 本地实例(必须选择 32 位版本 - 所以,较旧的版本)。 我
1、备份 <% SQL="backup database 数据库名 to disk='"&Serve
1、ASP中怎么实现SQL数据库备份、恢复! 答:asp在线备份sql server数据库: 1、备份 <% SQL="ba
我在 R 中使用 stats::filter 函数来理解 R 中的 ARIMA 模拟(如在函数 stats::arima.sim 中)和估计。我知道 stats::filter 将线性过滤器应用于向量
我已经浏览了示例应用程序的文档和代码,并发现 files/objectbox/objectbox/data.mdb 是存储所有数据的默认文件。 假设我的理解是正确的,我有几个问题找不到文档: 我想在我
为了恢复非续订订阅类型的 InAppPurchase,我已经实现了服务器来处理此问题。 但在购买过程中,iTunes 有时不会要求用户验证他们的卡详细信息, 在这种情况下,它会在后台发送应用程序并显示
我的问题是寻找cocos2d游戏期间暂停/恢复状态(包括所有需要保存的数据信息)的设计解决方案。 包括但不限于以下情况: 1).用户选择退出,然后弹出一个对话框供用户选择“直接退出”、“暂停”; 2)
在 Mercurial 中,我有一个旧的变更集,除了对单个文件的更改外,它都很好。我将如何恢复对该单个文件的更改? 即使只是能够在上一个变更集中查看文件的状态也会很好,然后我可以剪切和粘贴。 我的 M
我的一项职能遇到了困难。我想做的是计时器在页面加载后立即启动,并且只有一个带有启动/恢复的按钮。我无法在代码中找出需要更改功能的位置。有人可以帮助我吗?谢谢! HTML: , Javascr
我正在阅读Scrap your type classes 。这为类型类提供了替代方案。然而,我被Paul Chiusano的评论所困扰。其中讨论了恢复 do 表示法 语法。 坦白说,我无法理解 ret
当 OrientDB 因某人重新启动机器而非正常关闭时,OrientDB 最终会处于数据恢复失败的状态。对于如何从这种不正常的关闭中正常恢复有什么建议吗?我们正在寻找系统在断电期间能够自行恢复的方法。
我正在构建一个 Electron 应用程序,如果发生崩溃,它必须重新加载渲染进程窗口。 目前我可以从主进程重新启动应用程序 app.relaunch(); app.quit(); 但我无法检测到窗口崩
我有 3 个 Activity ,比如说 MainActivity、 Activity 2 和 Activity 3。 在 MainActivity 中,我有一个按钮(开始/停止),当我单击此按钮时,
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 11 年前。 Improve thi
Twilio 是否支持暂停和恢复内容播放。换句话说,我有相当长的文件将播放给调用者,并且我正在尝试找到一种方法来实现暂停和恢复功能。在播放某些内容的过程中,我希望用户能够按数字暂停,然后再次按数字从音
我已经提交了 A、B、C、D 和 E。我意识到在提交 B 中发生了一些非常糟糕的事情,所以我想回到 A,这次正确地进行之前搞砸了 B 的更改,然后重新应用 C 、 D 和 E 自动。 您可能想知道为什
我的一个文件被“标记为文本”,图标也发生了变化。实际上这是一个 PHP 文件。我尝试过使用 Help -> Find Action -> Mark As 尝试将其恢复为 PHP 突出显示,但它不起作用
我有一些 SSE 程序,可以将循环中的内存归零,当指针未对齐时,它会引发 SIGSEGV进入我的处理程序。我可以在此类处理程序中获取更多信息吗例行公事,现在我不知道它是在哪里完成的,我也可以吗以某种可
我是一名优秀的程序员,十分优秀!