How do I check out a specific version of a submodule using 'git submodule'?

GitVersion ControlGit Submodules

Git Problem Overview


How would I go about adding a Git submodule for a specific tag or commit?

Git Solutions


Solution 1 - Git

Submodule repositories stay in a detached HEAD state pointing to a specific commit. Changing that commit simply involves checking out a different tag or commit then adding the change to the parent repository.

$ cd submodule
$ git checkout v2.0
Previous HEAD position was 5c1277e... bumped version to 2.0.5
HEAD is now at f0a0036... version 2.0

git-status on the parent repository will now report a dirty tree:

# On branch dev [...]
#
#	modified:   submodule (new commits)

Add the submodule directory and commit to store the new pointer.

Solution 2 - Git

> Step 1: Add the submodule > > git submodule add git://some_repository.git some_repository > > Step 2: Fix the submodule to a particular commit > > By default the new submodule will be tracking HEAD of the master branch, but it will NOT be updated as you update your primary repository. In order to change the submodule to track a particular commit or different branch, change directory to the submodule folder and switch branches just like you would in a normal repository. > > git checkout -b some_branch origin/some_branch > > Now the submodule is fixed on the development branch instead of HEAD of master.

From Two Guys Arguing — Tie Git Submodules to a Particular Commit or Branch .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser775171View Question on Stackoverflow
Solution 1 - GitjoemallerView Answer on Stackoverflow
Solution 2 - GitfsenartView Answer on Stackoverflow