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

I am really disappointed in using the git submodule function. Either I still do not understand, or it just does not work, as I expect it to. The following design situation is provided:

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

In this scenario, source points to another repository containing common source data in all of our projects. There are many events occurring in the source , as well as in projsrc . Unfortunately, the Project points to some fixation of the original submodule, and not to the actual HEAD. This is the usual git behavior, as I understand it.

I already found out that

 git submodule update 

just get the version of the submodule that was transferred along with the main project. Nevertheless, I would really like you to always be aware of the development of submodules, but do not know how to do it correctly. So my question is:

Is it possible to attach the Project to the HEAD submodule, regardless of whether it violates the compilation of the project or not. I just don't want to always go into a submodule directory and pull git there. Since I think that I can lose my changes in the submodule directory, because it is simply related to commit and not really a single branch or so.

Consider the following restrictions :

  • The developers of our group are not familiar with all VCS. We used to use a really huge svn repository before, without any external repo functions at all.
  • We are working on Windows
  • A click'n'forget solution would be better, since most project participants were afraid to use the command line interface :)
+6
source share
3 answers

The reason why the submodule indicates a specific revision is important. If you point to HEAD, assemblies will not be reproducible . That is, if you check the version of the project yesterday, you will never know which version of source @HEAD was yesterday.

This is why it always saves a specific revision of sha.

To pull out all submodules, you can use the Easy way to pull out the last of all submodules.

+7
source

I am not good at Git and the submodule. But I think some simple rules will be very useful.

  • Commit and click from the subdirectory.
  • Go back to the root of your project, check the status if you need to commit and click again.

at Pull. may try to use a script to merge the pull / subodule update together. And do it only at the root of your project.

+2
source

Consider this:

  • the source points to HEAD (as you would like).
  • you make changes to the source within you Project (you commit but don’t click them)
  • you now have two HEADs: one in your Project source, the other in your shared source.

Which of them would you like to be present in your project when updating the submodule?

The problem (and the main function) of git in your case is that you see commit and push as an atomic operation. This is not true. git is decentralized. There is no common HEAD. You can have multiple repositories with different HEADs.

Consider this:

  • you have 3 developers (A, B and C) with a git project.
  • they all pull out the HEAD project.
  • each developer made changes to the project
  • Now each of them has 3 HEADS: HEAD, B HEAD and C HEAD.

Which HEAD do you consider to be "true" HEAD?

So, to answer your question: if you want the common source submodule to always synchronize with the central repository, git is not your choice. And probably none of the VCS will help you with this.

You should consider the git submodule as a third-party library that needs to be updated manually using these two steps:

  • Pull your submodule ("download thirdparty library")
  • Fix your project with the updated submodule ("put the new thirdparty library into your project")

If you want to make changes to a submodule, you must do the same in reverse order:

  • Lock your submodule ("make changes to the third-party library")
  • Click your submodule ("submit your changes to a third-party third-party library")
  • Fix your project with the updated submodule ("put the new thirdparty library into your project")
+2
source

Source: https://habr.com/ru/post/900275/


All Articles