简体   繁体   中英

Git submodule mess: how to use git submodules with developers not familiar with git?

I am really frustrated about using git's submodule feature. Either I still don't get it right or it just don't work as I am expecting this. Following project situation is given:

Project
  | .git
  | projsrc
  | source (submodule)
  | proj.sln

In this scenario source is pointing to another repository containing the common source data across all our projects. There is a lot of development happening under source as also under projsrc . Unfortunately Project points to some commit of the source submodule and not to the actual HEAD of it. This is the usual git behaviour, as far as I got it know.

I already found out that

git submodule update

just get the version of submodule which was commited together with the main Project. However, I would really like to be always up-to date with the submodules development, but do not have any real clue how to do this right. Hence my question is:

Is it possible to attach the Project to the HEAD of the submodule, reagardless of the fact if this will break the compilation of Project or not. I just don't want to go always into the submodule directory and do git pull there. Since I think I could loose my changes done in the submodule directory, because this is simple attached to a commit and not really to any branch or so.

Please consider following constraints :

  • Developers in our group are not that familiar with all VCS around. We are used to use really huge svn repository before, without any external repo features at all.
  • We are working on Windows
  • A click'n'forget solution would be best, since most of project members are rather scared by using a command line interface :)

The reason why a submodule points to a particular revision is important. If you point to a HEAD, builds will be unreproducible . Ie if you checkout yesterday's a version of the Project, you would never know which exact version of source@HEAD was yesterday.

That's why it always stores particular revision sha.

To pull all submodules you could use Easy way pull latest of all submodules

I am not good at Git and submodule. But I think some simple rules would be very helpful.

  1. Commit and push from sub-directory.
  2. Go back to root of your project, check the status if you need to commit and push again.

when Pull. can try to use script to bundle the "pull/submodule update" together. And only do it at the root of your project.

Consider this:

  1. source is pointing to HEAD (as you would want).
  2. you make changes to source inside you Project (you commit but not push them)
  3. now you have two HEADs : one in your Project's source, another in your common source.

Which one you would want to be present in your Project when you make submodule update?

The problem (and the main feature) of git in your case is that you consider commit and push as atomic operation. It isn't. Git is decentralized. There is no common HEAD. You might have multiple repositories with different HEADs.

Consider this:

  1. you have 3 developers (A, B and C) with a git project.
  2. they all pull a project's HEAD.
  3. each developer has made changes to project
  4. now each of them has 3 HEADS: A HEAD, B HEAD and C HEAD.

Which HEAD you consider "true" HEAD?

So, to answer your question: If you want common source submodule always be synchronized with central repository, git isn't your choice. And probably none of VCSs would help you with that.

You should treat git submodule as a thirdparty library which should be updated manually with these two steps:

  1. Pull your submodule ("download thirdparty library")
  2. Commit your project with updated submodule ("place the new version of thirdparty library to your project")

If you want to make changes to submodule you should do the same in reverse order:

  1. Commit your submodule ("make your changes to the thirdparty library")
  2. Push your submodule ("send your changes to the thirdparty library maintainer")
  3. Commit your project with updated submodule ("place the new version of thirdparty library to your project")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM