This article introduces using IDEA to control Git operations
Associate a local Git client
First install the Git client according to the system environment
Then use File --> Settings --> Version Control --> Git to configure the client installation directory
Create a local repository
Create your own project based on project requirements
Then use VCS --> Import into Version Control --> Create Git Repository... to create a Git repository on the project
After the creation is successful, the .git directory will appear in the project folder
clone remote repository
We can clone a Git project in two ways.
The first is to clone the Git project locally through other tools (such as Git Bash), and then use IDEA to open the project directly. File --> Open...
Second, use IDEA to import the project directly from the repository. File --> New --> Project from version control --> Git
We need to fill in the Git repository URL, storage directory
Submit code
If we want the file to be managed by Git, then we need to add the file.
In IDEA, we only need to set add to a file once, and then we don't need to add it manually.
Right click on the file --> Git --> Add
When submitting code, we use the file right-click --> Git --> Commit Directory... to commit
branch management
Branch management is mainly concentrated in the operation area in the lower right corner of IDEA.
Main menu function
New Branch : Create a new branch from the current branch. The above figure is to create a new branch from the master branch.
Checkout Tag or Revision : Checkout a temporary branch using branch, tag or commit code.
Local Branches : List of local branches. At the same time, the corresponding remote branch is displayed.
Remote Branches : List of remote branches.
local branch menu
Checkout : Check out this branch.
Checkout As... : Use this branch to create a new branch and checkout to the new branch.
Compare With... : Compare code commits using the current branch and the selected branch.
Rebase Current onto Selected: Do a rebase on the current branch. (Add the selected branch commit to the current branch)
Checkout with Rebase : Checkout the selected branch and do a rebase. (Add the current branch commit to the selected branch)
Merge into Current: Merge into the current branch (merge the selected branch into the current branch)
Rname: Modify the selected branch name
Delete : delete the selected branch
remote branch menu
Checkout As... : Create a new local branch using the remote branch, and checkout this branch.
Compare With : Compare code commits using the current branch and the selected branch.
Rebase Current onto Selected : Rebase on the current branch. (Add the selected branch commit to the current branch)
Merge into Current: Merge the branch (merge the current branch with the selected branch)
Delete : delete the selected branch
Push the local branch to the remote repository
Check out the branch you want to push, then right-click on the project --> Git --> Repository --> push
When pushing, there will be a new label prompt to create a new branch remotely
Tag management
Check out the branch you want to tag, then Git --> Repository --> Tag...
Push local tags to remote repositories
Right click on the project --> Git --> Repository --> push
Then select Push Tags at the bottom. We can choose to push all tags or the current branch tag.
Code pull and push
Right-click on the code pull project --> Git --> Repository --> pull
Right click on the code push project --> Git --> Repository --> push
rebase operation
common rebase
Select the branch to perform the rebase operation. It should be noted here that the current branch is the patch branch, and the selected branch is the base branch. That is to say, the current branch commit will be added after the selected branch commit.
merge commit (interactive rebase)
We can merge commits in the local branch before the code is pulled. This will make the remote branch not care about the local development process log, and make the remote log clean and tidy.
log before rebasing
Find the first log to be merged, then right-click and select Interactively Rebase from Here... to interactively rebase
(This option may not be available in lower versions of IDEA, please update to version 2018 or above)
Except for the title one, all other options squash are submitted together with the previous submission
Edit interactive rebase commit instructions. By default, the contents of all commits merged are displayed, and we can also add and modify contents.
log after rebasing
View the commit log
log tab
View the console
console tab. In the console we can see the git command actually executed, which can help us find the problem.
storage work area
Sometimes we need to temporarily store the code we are writing, then modify some bugs, and restore them after completing the bug modifications. At this point we can use code storage.
Right click on the project --> Git --> Repository --> Stash Changes
Fill in the storage name
This is where we will find that the modified code is gone.
After that we're going to restore the contents of the stash
Right click on the project --> Git --> Repository --> UnStash Changes
Select the staging name to restore and restore the staging
At this time we found that the modified code came back
commit fallback
If we want to discard the content of the last commit, we can use commit rollback
log before rollback
Right click on the project --> Git --> Repository --> Reset HEAD...
Perform rollback (add a few ^ after HEAD to roll back several commits)
post-execution log
Manage remote warehouse addresses
Right click on the project --> Git --> Repository --> Reotes...