Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate git with Idea

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to integrate Idea git, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

First, let's take a look at the common command diagram of git.

As we can see from the picture above, git is divided into four parts, of which three are local, namely, the workspace, the staging area and the background warehouse. It is important to note that if the file in the cache area is not committed to the local library, it is invalid. Because git is a version control tool, each submission will generate a version and this version number will only be generated when the code is submitted, so when the file in the temporary storage area is not submitted, it is equivalent to not generating a new version, the consequence is that even if you change the file in the workspace, the corresponding code of the branch is still unchanged. For example, when you are on Branch A, you modify some files but do not have commit, and then you switch to Branch B, and the temporary storage area will be emptied. When you switch back to Branch A, you will find that the code you modified last time on Branch An is gone. So don't forget commit when you modify the code. Except for the different location, the local warehouse and the remote warehouse are all the same, they all contain the corresponding resources of each branch, and the branch switching is the switching of the workspace. The instructions shown in the figure above are basically all the instructions we use in normal development. Many people will make all kinds of mistakes when they still use git after understanding these things, such as push failure, pull failure, merge conflict, or merge does not report an error later, but the code cannot run without knowing why, and so on. Some problems can be solved by version fallback. Again, the local code is completely paralyzed and cannot be run up at all, so it can only be deleted and re-downloaded, which is time-consuming and laborious. I am afraid that when the project is in a hurry, I may want to die. I don't know if you have such an experience. Anyway, I have experienced it several times. Later, when I thought about it carefully, I found that most of the problems were caused by the irregular use of git. So here I suggest that you should pay attention to the following points when developing: 1) every time you modify the code, you must pull again to make sure that the local code is the latest version; 2) every time you write a new requirement, you'd better create a new branch, and do not modify it on a branch all the time; 3) every time the code is written and submitted, it is best to delete the local and remote branches. 4) the push code must be correct, otherwise it is easy to be beaten. 5) Don't be blind if you don't understand the instructions.

2. IDEA integrated git method

First of all, idea integrates git. We need to download a small software, git bash address: https://git-scm.com/downloads. After downloading, go straight to the next step, fool, and try to install it. After installation, there will be a git folder under the folder you specified. The file structure is as follows:

Of course, if you are familiar with git commands, you can use this software to achieve all git operations. Let's integrate it into the IDEA development tools. Open the IDEA software.

Step 1: open it according to the following picture.

Step 2: you will see a pop-up box and open it as shown in the figure:

After completing the above steps, click OK. In this way, IDEA successfully integrates git.

III. Common operations

1) leave the code to Git to manage

VCS-- > Enable Version Control Integration...

-- > Select the version control system you want to use, select Git-- > OK

When you are finished, the above prompt appears under IDEA. At this point, the project has been associated with Git, that is, the project has been handed over to Git management.

2) submit the code to the local warehouse (commit)

After handing over the project to Git and then clicking VCS, you will find that the listed options have changed.

VCS-- > VCS Operations Popup...

Click VCS Operations Popup... What comes after that is what Git can do. Because it is submitted locally, click commit.

-> commit...

Then the following window appears. The top part of the window is to select the document to be submitted, and fill in the memo information for each submission in the Commit Message section.

-> commit

Before submitting, IDEA will remind the project that there is a problem, select review to view the problem, and select commit to ignore the problem and submit it directly.

Commit is selected here. Then a green prompt appears below the ide

At this point, the code has been submitted to the local warehouse.

It should be noted that the local warehouse address is the project address by default.

3) View the submission history of the code

Right-click the project-- > Git-- > Show History

The area at the bottom of the screen displays the submission history of the project. Double-click the options in it to show each submission in detail.

(two submissions were made here, with only .java files submitted for the first time and other documents for the project for the second time.)

4) submit the code to the remote warehouse (push)

VCS-- > VCS Operations Popup... -> Push...

The above window appears because you have not selected a remote warehouse to connect to, so you need to specify the remote warehouse

-> Define remote

Here, you need the url of the remote warehouse. Log in to your own GitHub and copy the url of a remote warehouse.

Paste

-> OK

-> Push

Git voucher management, enter the account secret of GitHub

Then type it once on IDEA, so type it.

Then wait for push, and push fails.

The blogger did not know why, but only found a solution online:

Try it according to the method said on the Internet, and it really worked.

Log in to GigHub to check

The submission already exists in the remote warehouse. At this point, push is complete.

5) Clone the project from the remote repository to local (Clone)

Check out from Version Control-- > Git

-> Clone

When the cloning is complete, you will be asked if you want to open the project.

-> yes

Open the project check and find that it is consistent with the previously uploaded content. At this point, you have finished cloning the code from the remote warehouse to the local.

It is important to note that because the clone is based on the url of the repository, all the contents of the repository will be cloned at the same time. For example, this clone has also cloned the project that the blogger previously uploaded with git in eclipse.

6) obtain other users' modifications to the project from the remote warehouse (pull)

Some people may not understand the difference between this and the former. Here is a brief explanation:

Clone-- made something out of nothing. It turns out that there is no local project, so clone the whole project from the warehouse to the local.

Pull-- is the icing on the cake. Project 1.0 already exists locally, but others modify the project to Project 2.0 and upload it to the remote repository. So what you need to do is to pull the changes made by others in the remote warehouse locally, and make your local project 1.0 become project 2.0.

After the instructions, we will start the operation now. First, we will prepare in advance:

First open the project for commit and modify it to upgrade it to Project 2.0

Then upload the code to the remote warehouse

It should be noted that commit must be carried out before push

Otherwise, no commits selected will be displayed

As for how to upload to the remote warehouse, we will not repeat it here, you can refer to the previous article. It is worth reminding that if you choose Commit and Push when commit, you can operate commit and push successively.

OK, now the changes to the project have been uploaded to the remote warehouse.

After the preparatory work has been completed, we will now officially proceed with pull:

Open "Project 1.0" of clone just now.

Well, it's fine, it's the same as usual, now pull and update it:

Right-click the project-- > Git-- > Repository-- > Pull...

-> Pull

Thank you for reading this article carefully. I hope the article "how to integrate Idea into git" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report