Catch up with qingming Festival back home, have not updated for some time, today say a simple and easy to use thing — git submodule.


background

A bit of background, if you have the same needs developers can use it. Because I need to rely on a module in my project, and this module is not maintained by me, but by students in other groups, they only need to tell me when they confirm to update it every time, so THAT I can update it, regardless of the code. At first I thought git would clone A module A outside of my project and import it with AS import, but I found that by doing this, AS would generate A new module B locally, which is just A backup of A, i.e., every time the A project is updated, The B module in your AS will not be updated. This was awkward, so I chose to use git subModule instead.

use

First switch the directory to your Project (yes, your Project) on the command line, and then

Git submodule add what you want to rely onmoduleGit addressCopy the code

Just like Git Clone, a new module (or project) appears in your project directory. Then you go to Android Studio, import the module you need, and rely on it as needed.

update

If you need to update something, just type the following command:

git submodule updateCopy the code

Can be

Switch branch

If you add git submodule and need to switch branches, you can simply CD into the project and use Checkout to switch branches only.

delete

First, delete the configuration information in the. Gitmodules file. Then, run git rm -cached to delete the submodule file from Git.

Teammate sync code

This was a bit of a cheat at first, I used git subModule and forgot to tell my colleagues, they synchronized the code and it didn’t work. Git subModule: Git submodule: git submodule: git submodule

git submodule update --init --recursiveCopy the code

conclusion

Simple enough, but useful for multi-module development, or for teams with several teams working together.


Finally, I recommend the public number, welcome to give me a message. For more development knowledge, you can pay attention to my public number: