Git Operation practice in IDEA:

1 Git configuration in Idea

1.1 install Git:

Git is a version control system, you can use Git to achieve team code version control and management, can be downloaded from the officialwww.git-scm.com/downloadDownload it (if it already exists, you do not need to download it), as shown in Figure -1:After you’ve downloaded Git, install it in a dumb-ass way. Don’t change the installation directory (don’t install it if it’s already installed).

1.2 Storage Model

The storage model of Git system is shown in Figure -2:

1.3 Global User Configuration

Open the Git client tool and configure the user and password to identify the user who committed the code.

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

Check the configuration information.

$git config - the listCopy the code
user.email=xxxxxx@xxxxxx.com
user.name=xxxxxx
Copy the code

1.4 Checking Git environment in Idea

Find the Git configuration options and conduct Git tests, as shown in Figure -3:

1.5 Gitee configuration in Idea

Step 1: Install Gitee plug-in. Open Plugins option in IDEA Setting, and then search and install Gitee plug-in, as shown in FIG. 4:Step 2: Check whether Gitee has been installed. Check the Gitee option in Version Control in Settings, as shown in Figure -5:

Step 3: Click the Gitee option of Version Control to configure the account for logging in Gitee, as shown in Fig.6:Step 4: In the Gitee configuration interface, select Add Account to enter the Account configuration interface, as shown in Figure 7:In the Gitee account configuration interface, configure the account connecting to the Gitee platform (you must register the Gitee platform account in advance), and then click Login to Login. After successful Login, the following interface will appear, as shown in fig.8:

2. Basic Git operations in Idea

2.1 Creating a Local Library Create a project local library in Idea, as shown in Figure -9:

The local library will be created in the root directory of your project, as shown in Figure 10:

When the local library is created, a.git directory (possibly hidden) will be added to the root directory of the disk project, as shown in Figure 11:

We can also view the location of the local library in idea, as shown in Figure -12:

After the local library is successfully created, when we create files in SRC /main/ Java, SRC /main/resources and other directories, we will be prompted whether to add the files to the temporary area, as shown in Figure -13:

If cancel is set, the file exists only in the workspace, and its file information is not added to the staging area.

2.2 Exclude file configuration

Open the exlude file in the. Git /info directory and modify its contents to filter for specific resources, such as resources that are not committed or uploaded. This file can be configured globally. The specific contents are as follows:

HELP.md
target/
out/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
.gitignore
### maven ###
mvnw
*.cmd
.mvn/
Copy the code

2.3 Git Add, Commit

Add the project and Module updates to the staging area and Commit the local library, as shown in Figure 14:

Alternatively, perform related operations based on the buttons on the toolbar, as shown in Figure 15:

When you commit a project, enter the commit information, as shown in Figure 16:

2.4 Version switching in Git

Step 1: Right-click on the module or select Show History in the toolbar to display the version submission history, as shown in Figure 17:

Step 2: Right-click the version to be switched and select Copy Revision Version, as shown in Figure -18:

Step 3: Right-click on the module and reset the head information, as shown in Figure -19:

On the reset page, set the reset type and commit version, as shown in Figure -20:

If the version switchover is successful, the version to be switched is displayed, as shown in Figure -21.

2.5 Project Share to remote warehouse

The Gitee remote code hosting platform that pushes projects and modules can be divided into two situations. One is that there is a remote repository, and the other is that there is no remote repository. In the case of no remote warehouse, we can directly share the code with CVS, as shown in Figure -22:

Specify the name of Gitee repository (the repository does not exist and will be automatically created during push), as shown in Figure -23:

Log in to Gitee and check the contents of the remote warehouse, as shown in Figure -24:

When the library project is updated, push operation can be directly carried out on the project, as shown in Fig.25:

2.6 Update the Local Repository

Normally, partners upload new code to Gitee. If the local library is not updated at this time, it cannot be uploaded. For the sake of simplicity, we directly modify the file online on Gitee. Step 1: Open the file to be edited and then select Edit. At this time, the file content will be opened, as shown in Fig.26:

Step 2: Edit the content online and submit it, as shown in Figure -27:

The third step is to update Git in IDEA, as shown in Figure -28:

Go straight to the first one and select OK

After the update is successful, see Figure -29:

2.7 Merge local and remote libraries

Step 1: Create a file in the remote repository, as shown in Figure -30:

Step 2: Edit the content of the new file, as shown in Figure -31:

Step 3: Submit the created file, as shown in Figure -32:

Step 4: Modify the contents of the local library, and then submit the data. If the data is rejected, select Merge, as shown in Figure -33:

After the Merge is successful, the files created by the remote library will be displayed in the project display area, as shown in Figure -34:

2.8 Cloning a Remote Library Project to the Local Computer

Open the option of Clone in IDEA, as shown in Figure -35:

Specify the clone address and the clone directory. If there is already a project with the same name to be cloned to the local location, you can change the new project name, as shown in Figure -36:

After the cloning is complete, select open the project window, as shown in Figure -37:

3 collaborative development based on Git in Idea

3.1 Collaboration between partners

In the collaborative development process of the project, if the remote repository is not created by you, after the code editing of the cloned project is completed, push code by your own account will fail (you are not allowed to push). At this time, if you want to upload successfully, you must ask the owner of the remote repository to add you as a partner. Take Gitee platform as an example to implement: The first step: Developer menu in warehouse management, and then invite users, as shown in Figure -39:

Step 2: Invite users by linking or directly adding, as shown in Figure -40:

Step 3: Wait for the invited user to agree to the collaborative development.

3.2 Collaboration between non-partners

There are a lot of good open source projects on GitHub that you can download and look at and borrow from. However, if we change the code, because we are not the partner of the other party, we cannot upload the code to the other party’s warehouse. At this time, we can choose to use fork and pullRequest operations. When you see your favorite project, fork it to make a copy of someone else’s project as your repository, and the repository will show you where the current project came from. As shown in Figure -41:

If you want to merge the code with the author, you need to ask the author for approval. Click Pull Requests →New Pull Request.

4 Summary (Summary)

4.1 Analysis of key and difficult points

▪ Git configuration in IDEA. Basic Git operation in IDEA. ▪ Git collaborative development process in IDEA.

4.2 the FAQ analysis

How to test Git environment in IDEA? How to install Gitee plug-in and account configuration in IDEA? How to switch Git versions in IDEA? ▪ How to push a project in IDEA to a remote repository? ▪ How to update remote warehouse changes to local in IDEA? How to clone an IDEA project to the local? How to import clone project in IDEA?

4.3 the Bug analysis

▪ Project push to remote repository failed. ▪ Imported clone project does not run