image

If you feel helpful welcome to pay attention to, appreciate, forward reading time: 2128 words 6 minutes

Introduction to version control

These are some of the things we need to think about before we start writing code

  • So how do you merge and manage code if you have multiple people working together?
  • What do I do if I need to mark a module after it has been developed?
  • If I run into a bug in an online application, how do I find the code online to fix the bug?
  • .

The answer is in the subtitle — we need version control. In simple terms, version control is about managing our code additions, deletions, changes, and reviews, and keeping track of every footprint we leave in the code by committing actions. In addition, it also allows you and your friends to collaborate on development, which is not hard to explain, without it, you and your friends to collaborate on the code? That’s cruel.

What are the version control tools?

The most common version control currently available in the market, and most commonly used by companies, falls into two categories (CVS, RCS, etc.) :

  1. Svn: Centralized version control
  2. Git: Distributed version control

And the biggest difference between them has been reflected in the above explanation above, distribution and concentration! Centralized, where all code commits are dependent on a central server, and each action is a pull and commit to the branch being modified locally. When we cannot connect to the SVN server, we cannot perform version operations.

Distributed: each developer has a complete version control system in hand, and does not need to rely on remote servers for version control management. After connecting to the “server”, it simply merges and synchronizes the entire repository. Servers are in double quotes because, in distributed version control, each terminal can exist as that so-called “server.” That’s decentralization!

Here are two pictures to give you a sense of the intuition (pictures from the Internet)




Image from Internet




Image from Internet


The last simple word: version control — both SVN and Git are a code time machine that records every important time node and can take us back to that node at any time!

Github installation and initial use

Github is the largest git (distributed version control) hosting platform for open source and proprietary software projects on the market. But its role and mission goes far beyond being a free hosting platform. For now, let’s see how it works as a free Git repository. So don’t worry, we will treat Github as git for the time being, and there will be a chance to show you how powerful Github really is

3.1 Installing and Configuring the Git Environment

Mac address: gitforWindows.org/ Windows address: gitforWindows.org/

Step 1: Install

If you install Xcode on your MAC, you can save yourself some work. Xcode is already integrated with Git. After installing win, you need the environment variable, then open CMD terminal, type git –version, but when you see the corresponding version number, it means that the installation is successful!

Step 2: Configure user information and email

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"
Copy the code

The –global parameter of the git config command indicates that all git repositories on your machine are configured with this parameter. But for corporate projects you want to configure corporate email, you can reconfigure the single project by dropping the global parameter into the corporate version control directory!

Step 3: Configure git win for AndroidStudio: Open File – >Settings – >Version Control – > git


The picture of the win







image







image

3.2 Creating a repository on Github

Gitbhub: github.com/

The first two steps of registration and login is not too much skill, is that you taste the registration of other accounts is not too big difference, here put two pictures of meaning, no longer repeat!

1. Register first


The sign-up page

2, login


The login page

3. Add an SSH Key to Github

If you don’t want to enter your password every time you push content from your local repository to Github. Then you have two options

  • Configure the Github account password in AndroidStudio as you did with Git


    image

  • The second is to configure the SSH key

Step 1: Generate a public/private RSA key pair

        ssh-keygen -t rsa -C "[email protected]"
Copy the code

By default, two files id_rsa and id_rsa.pub are generated in the corresponding path (/your_home_path)

Step 2: Paste SSH Key Use the following command to copy the contents of sshkey to the clipboard MAC

        pbcopy < ~/.ssh/id_rsa.pub
Copy the code

win

        clip < ~/.ssh/id_rsa.pub
Copy the code

Step 3: Add sshKey to Github




image

4. Create a new warehouse

Once logged in, click the ➕ number in the upper right corner of the home page and select New Repository


The new warehouse







image



Note:








5. Initialize the local repository and synchronize to the github remote repository you just created


image


We use the command line to create a new Repository and synchronize it to the remote repository, taking the hint in the red box above as an example




Initialize a local repository and synchronize the remote


Here’s what happens when you refresh the Github page:




Check out the newApp project on Github


3.3 Create a Branch of Develop and push it to Github

1. Introduce some git commands

// Create a branch called develop from the current branch. Git add. // Commit the code from the repository to the local git repository Commit -m" commit log" // Synchronize the local branch to the remote repository. git push origin developCopy the code

2, do not want to submit files to add. Ignore file

There are always some files in our project that we don’t need to commit, so we can add them to an.ignore file. We ignore writing the file backwards when we do git add.




Ignore file content


Of course, git has already created this file for me when we created the project, so we don’t need to do anything for now.

3, actual practice


Open a new Develop branch from Master and sync to Github

After I run git status, you will see the idea folder, which is not necessary to submit. A close look at the ignore file shows that the default ignore file only helps me add three files from IDEA to the ignore file. So I changed the.ignore file up there. will

/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
Copy the code

Change to

/.idea
Copy the code

Therefore, git status must be used frequently to check the status of files in our project.

If we open up our newApp project on Github again, click on Branch Master to see the Sync Develop Branch that we just committed.




Check out the updated Develop branch on Github

Git branch Management is a very important tool for Git branch management. It is a very important tool for Git branch management. Git branch management is a very important tool for Git branch management.

Write at the end

I didn’t know until I wrote the article. A lot of things, it is difficult to do all things, regardless of size. Whether it’s the places I thought I could ignore or the places I didn’t think I could ignore. In the article should have appeared, if you have any questions, you can comment on the public account can also leave a message behind. I hope you will forgive me.

Finally, you may find that your Theme is not quite the same as mine. I used a plugin called “Material Theme UI” from Aandroid Studio, and chose the black Theme from AndroidStudio, so it looks different from yours!

If you like, you can reply “Settings” in the background of the official account, and you can get the Settings of my AndroidStudio. I’ve already exported my Settings, along with a lot of nice plugins that we use all the time (I’ll probably cover them in (4)).

Once you have the JAR package, go to File-> Import Settings to Import it


Welcome to pay attention to my public number