Project management cannot be separated from version control. Currently, the mainstream version control tools are probably SVN and Git. As for the difference between the two, I will not introduce them in detail here. If you don’t understand, you can search for information online. If you have the opportunity in the future, I will start the column in detail. Moreover, the usage rate of Git on the market is far higher than that of SVN. How do we proficiently use Git to control code versions when using IDEA development projects?
1. Install Git
Of course, you need to install Git first. The installation process will not be explained in detail. After pressing the installation, open IDEA and enter the settings interface (you can directly click on the toolbar, or you can search for git through the shortcut keys Ctrl + Alt + S). The interface is as follows:
We can see that Git is in the Version Control tab, and there is also a GitHub in it. You can configure your GitHub account and password, and then you can directly pull down the code on GitHub. For more information, please refer to the previous articles about Settings.
Let’s continue to talk about Git. Path to Git executable is the git.exe in the bin directory in our local Git installation path. After routing the path, click the Test button. If the installation is correct and the path is correct, the following dialog box will pop up, indicating that the configuration is successful:
2. Remotely pull the Git library code
We often pull the code on the company's Git library or GitHub to locally develop. How do we pull it in IDEA? In fact, there are two ways to achieve our goals. Let’s take GitHub as an example:
1. First pull the code locally through git tool, and then open it through IDEA.
Copy path
Clone to local
lq@DESKTOP-BHJ6UD2 MINGW64 /e/mygit/20180226 (master)$ git initReinitialized existing Git repository in E:/mygit/20180226/.git/lq@DESKTOP-BHJ6UD2 MINGW64 /e/mygit/20180226 (master)$ git clone https://github.com/noobgod/designPattern.gitCloning into 'designPattern'...remote: Counting objects: 73, done.remote: Total 73 (delta 0), reused 0 (delta 0), pack-reused 73Unpacking objects: 100% (73/73), done.
The pull is successful, the path is in local E:/mygit/20180226, open the project under this path in IDEA, and follow the steps.
2. Pull the code directly through IDEA, which is recommended because it is convenient and fast.
After selecting according to the above picture, there are multiple options available. If we select Git, a dialog box will pop up and click the Clone button.
3. Update (update)
Before submitting the code, it is best to update the code of the remote repository to the local repository, which can reduce unnecessary conflicts. Updating update can be achieved directly through the shortcut key Ctrl + T or by pressing the keys on the toolbar, namely update, commit, and compare with the same repository version. Here we choose update.
Of course, you can also right-click the project --> select Git --> Respository --> pull to achieve it.
4. Commit and push
How do we submit our own code to the remote repository after we develop our own code in IDEA? Right-click the project -->Select Git
1.Commit Directory: commit code (submit the temporary files in the stage area to the local repository of the current branch and clear the stage area), or push code (synchronize the files of the local repository to the remote repository).
In IDEA, we see that the file is marked with different colors: red, green, and blue. What do they mean?
Red: Files that are not versioned, i.e. files that are not added to versioned, such as files that we add to ignore.
Green: The newly added version of the file, that is, the file we have newly created, has not been submitted to the remote repository.
Blue: The modified file, that is, the file already exists in the remote repository. We have modified it this time, but have not submitted it yet.
Commit corresponds to Git's Commit command. Sometimes we only want to commit to the local repository but don't want to push it yet, so we can use this method. If we need to push to the remote repository after commit, we need to right-click the project --> select Git --> Respository --> push.
To implement the simple commit function, we can also use the shortcut key Ctrl + K, or the toolbar button.
Commit and Push are Commit and push. We can directly commit to the local repository here and then push to the remote repository.
2.Add: Add local files from the working directory to the stage area of the local repository, corresponding to the Add command of Git.
3.Compare with Branch…: Compare with remote branches. Before submitting, we can use this function to compare the similarities and differences between the code in our working directory and the remote branch code.
4.Show History: View historical modified version records.
5.Revert: Rollback will roll back your local modifications.
6.Repository: Various repository commands.
5. Merge
During development, multiple people will inevitably encounter modifications to the same file, causing version conflicts. At this time, if the program needs to run normally and ensure complete functions, developers need to manually resolve these conflicts and merge the code to obtain the final consistent code and then push it to the remote.
This area is often the most troublesome for many people. Improper operation may cause code disorder and accidents. In fact, if you understand the principles, you will not be that complicated after you are proficient.
There is a lot of content to be introduced here and needs to be explained in detail. If you are concerned about this, you can pay attention to it and add and improve it in the future.
6. Branch management
For branch management, we need to use the status bar at the bottom of IDEA.
Here we can switch branches, create new branches, checkout branch code, compare branch code, etc.
Summarize
The above is the tutorial on using git in IntelliJ IDEA introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!