Music of the Day:

1. Basic Introduction:

  • In the process of Android componentization, it is easy to reuse modules when projects are large, or multiple projects share modules. At this time, the common modules of the Project need to be extracted, and now git is basically used as a version control tool, so that the App Project has multiple modules, each module is an independent Git repository. And we hope that individual modules can be maintained independently, so that it is easier to view and synchronize updates anytime and anywhere.
  • To achieve this we can use git-submodule, git-repo, gitslave, git-subtree.
  • Git-repo is more suitable for managing large projects with many modules that change frequently. Android source code is managed in this way. If there are fewer modules, using git-subModule is sufficient.

2. Use steps:

  1. Enter the command into the main project root directory:
    • Git submodule add: Import the subModule from the remote repository into the project, which is automatically generated. Gitmodules file.
    • Git submodule add < submodule git address >: Imports submodules from the remote repository into a specific folder in the project.
    • git submodule init: Initializes the local. Gitmodules file.
    • git submodule update: Updates child Module changes in the parent project.
    • git submodule foreach git pull: Pulls all submodules.
    • git submodule foreach git submodule updateThis can be used if your subModule depends on subModulegit submodule foreachCommand to implement a one-time full update.
    • Git clone --recurse-submodulesGet the source code for the main project and all subprojectsGit pullWill not get the source code for submodules at the same time.
  2. Go to the submodule directory and type the command:
    • Go through the normal git add, git commit, and Git push processes.

3. Attention points:

3.1 Update subModule pit

  • In the parent projectgit pullOnly the code in the parent project is updated, not the code in the child Module project, and the call is forgottengit submodule update, thengit pushIt is highly likely that the old SubModule dependencies will be submitted again.
  • git pullAfter that, execute immediatelygit statusIf the subModule is modified, execute it immediatelygit submodule update.
  • If your subModule depends on the SubModule, then you probably need to use thegit pullgit submodule updateAfter that, execute again in each SubModule separatelygit submodule update, can be used heregit submodule foreach git submodule updateCommand to implement.

3.2, Modify subModule pit:

  • The defaultgit submodule updateThe subModule is not cut to any branch, so by default the submodule HEAD is in a ‘detached HEAD’ state. So be sure to use it before modifying itgit checkout masterSwitch the current SubModule branch to Master before you can make changes and commit.
  • If you forget to switch to the master branch and commit, you can save it with the cherry-pick command. Specific practices are as follows:
  • withgit checkout masterWhen you switch HEAD from free to master, Git will warn that a commit is not on branch. Remember the change-id of the commit (if the change-id is aAAA).
  • withgit cherry-pick aaaaTo apply the commit you just made to the master branch.
  • withgit pushCommit the update to the remote repository.

Delete subModule pits:

  • Deleting a submodule directly cannot completely delete it, and an error will be reported when adding it again'<submodule>' already exists in the index.
  • You can remove the SubModule completely with the following command:
Git rm --cached subModule project name rm -rf Submodule project nameCopy the code

Reference: blog.devtang.com/2013/05/08/…