Git submodule track commit but know branch?

邮差的信 提交于 2019-12-06 12:18:50

问题


I am working in a project where we use git submodules for purposes of tracking the code as whole (Several different parts which are released together) so I like the idea that submodules tracks a specific commit since what submodules will mostly be used for are history purposes.

This is nice so that in the future one can checkout a specific tag of the super repo and find out where the code was at for each component. An issue arises though if all of a sudden you want to perform some more commits to that specific version because since you are in a headless state there is no real way to find out which branch that commits belong to.

Tracking branches, as has been added in 1.8.2, doesn't seem to solve the issue either from what I can read as that will just checkout the latest commit in a branch which may not be what was released at the time.

Is there some sort of way to mix the 2 where one can checkout the super repo and see which commit everything was at then but still be tracked to a branch so that he knows exactly which branch to pull from (As they may have been more commits to that branch) and keep commiting to it?

I guess what I am looking for is to somehow have git fall in a state as if the developer had several commits to pull down from the server where his local repo head is at the right commit but the server has moved ahead, this way he could know exactly where he is at and easily do a pull to get latest commits for that branch. Or just have git submodules track tags (maybe?).

Am I correct in saying that technically, if tell a submodule to track a branch, I can omit the --remote from "git submodule update" command to get the specific commit (If I were, to say, checkout a commit/tag while in the submodule folder and commit the changes to the super repo) and get the specific tag and later on add the --remote to yet another "git submodule update" to end up in the branch pertaining to that commit, somewhat solving the whole issue?

Any input on the matter is appreciated.


回答1:


Tracking branches, as has been added in 1.8.2, doesn't seem to solve the issue either from what I can read as that will just checkout the latest commit in a branch which may not be what was released at the time.

Then simply make sure that your submodule is tracking a "release" branch, from where you can chose to create your own, and add more commits.

Remember that, even when following a branch, a git submodule update --remote with git fetch and update the submodule, but always leaving it in a detached HEAD mode.

See "Git submodule to track remote branch".

It is up to you to then define the branch in which you want to work on.

If you were already working on a dedicated branch of your own within that submodule, use, to update it:

git submodule update --remote --rebase

That will rebase your current work on top of the updated submodule.



来源:https://stackoverflow.com/questions/20109215/git-submodule-track-commit-but-know-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!