要获取包含子模块的项目,请在克隆项目后运行此命令:
git submodule init
Run Code Online (Sandbox Code Playgroud)
此命令.gitmodules将有关模块的信息读入和写入索引.
然后你跑
git submodule update
Run Code Online (Sandbox Code Playgroud)
它获得了子模块存储库的特定提交.
git如何知道特别提交哪个提交?这些信息存储在哪里?
我不理解这一点的原因是因为我可以看到它不在,.gitmodules但我认为它也不太可能在索引中,因为它将它git submodule init写入索引.所以它让这些信息没有合理的地方,我能想到的.
回答上述问题后,我们如何更改此提交编号,以便下次可以在不同的提交中检索子模块?
注意:我读过这个,这个和这个.我可能错过了,但我找不到问题的答案.
更新1
我想澄清下面关于larsks的答案.这是很好的答案,但我想澄清以下内容.
在答案中,使用git checkout a18306f命令.我想看看我是否有一个快捷方式来为分支上的最新提交执行此操作.为了运行此命令,我需要这样做:
git branch
## Note the current branch name, let's assume it's master,
## use this branch name in the following command
git log -1 origin/master
## Now note the commit number.
## This is where a18306f in the example above comes from in my use …Run Code Online (Sandbox Code Playgroud) 我运行了该git log --oneline命令,然后运行了git checkout <commit-id>之前的一些提交。我收到消息“HEAD 现在处于分离状态......”。现在我不知道如何回到最新的提交。返回最新提交的命令是什么。我们什么时候使用此功能来签出以前的提交版本。当我在探索 git 时运行 checkout 命令时,请告诉我。另外我们如何知道指向哪个提交HEAD?