Git 子模块:指定特定的 SHA?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8813249/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 06:19:51  来源:igfitidea点击:

Git submodules: specify a specific SHA?

gitgit-submodules

提问by Zubin

I'm referencing a git submodule in my project, and now need to reference a specific SHA in the target git repo.

我在我的项目中引用了一个 git 子模块,现在需要在目标 git repo 中引用一个特定的 SHA。

# .gitmodules
[submodule "vendor/plugins/ssl_requirement"]
  path = vendor/plugins/ssl_requirement
  url = git://github.com/retr0h/ssl_requirement.git

The SHA I want is bc96ad96407a72a60e0542cf3b0cecc6ff9e278e.

我想要的 SHA 是bc96ad96407a72a60e0542cf3b0cecc6ff9e278e.

回答by Lily Ballard

Submodules, by definition, always reference particular SHA1 in the subproject. That SHA1 isn't expressed in the .gitmodulesfile, but is instead expressed as the entry in the tree object that contains the submodule. The way you set this in git is by cding into the submodule, checking out the SHA1 you want, then cding back to the parent repo and committing your change, which will show up just like a changed file.

根据定义,子模块始终引用子项目中的特定 SHA1。该 SHA1 未在.gitmodules文件中表示,而是表示为包含子模块的树对象中的条目。您在 git 中设置它的方法是cd进入子模块,检查您想要的 SHA1,然后cd返回到父存储库并提交您的更改,这将像更改的文件一样显示。

So in your case what you can do is

所以在你的情况下你可以做的是

cd vendor/plugins/ssl_requirement
git checkout bc96ad96407a72a60e0542cf3b0cecc6ff9e278e
cd ..
git add ssl_requirement
# commit whenever you're ready