16

Assuming the following project layout:-

mainrepo_git
    |____ .git
    |____ .gitmodules
    |____ proj            <------- directory containing the code files for mainrepo
            |____ 3rdpartysourcecode <-- directory containing upstream open source code
            |      |____ .git
            |      |____ 3rdpartyfiles
            |
            |____ mainrepofilesanddirectories  

mainrepo_git contains source code I am directly responsible for. I have read/write access and can push and pull directly to a remote git repository which I manage.

Nested inside mainrepo_git is a directory which I named 3rdpartysourcecode. This 3rdpartysourcecode directory is in fact another git repo (also commonly referred to as a "git submodule") which is pointing to an open source 3rd party git repository managed by other developers. I only have read access to it. No write access.

Is there any way of 'freezing' a specific commit hash of the git submodule in relation to a commit made in my main repository?

For example, if I am at (or I revert to) commit a12ucak in my mainrepo, my git submodule also gets reverted to a specific version which I tie to commit a12ucak? And when I switch to commit b349jdsak, my git submodule also gets reverted to a version which I tie to b349jdsak?

So my question is: there is a way to create a linkage between a specific commit in the main repo with a corresponding commit in the git submodule? In such a way where when I checkout that specific commit in the main git repo, the corresponding commit in the git submodule will also be checkout.

Calvin Cheng
  • 35,640
  • 39
  • 116
  • 167

1 Answers1

12

Freezing is the whole point of submodules. You should really read a tutorial on it. In a nutshell, git add 3rdpartysourcecode (important no trailing slash!) followed by a commit locks the currently checked out submodule commit to the supermodule commit. Then later you use git submodule update to check out that revision.

Karl Bielefeldt
  • 47,314
  • 10
  • 60
  • 94
  • 2
    Correct. See also http://stackoverflow.com/questions/1979167/git-submodule-update/1979194#1979194 – VonC Aug 30 '11 at 05:42