(vii) GIT operations in Intellij

Source: Internet
Author: User
Tags commit

The GIT principle will be introduced in chapters later, this time mainly say IntelliJ how to operate git. IntelliJ has a good git interface, you can pull the code, pull the branch details, submit the code to the local repository, submit the code to the remote repository, you can merge the local branch, merge remote branch, you can switch branches freely, can solve the conflict caused by the merge problem. In summary, you can complete the basic git operation, as detailed below.

1. Update code

Ctrl+t, the code for the remote repository is updated. (PS: The default update selects branch default and using stash, so you can look at other options.)


2. Submit Code

Ctrl+k, if the local code does not change, it will prompt, no changes detected (no change detected). If the local code changes, you can commit, for Git commits, the first is to commit to the local repository (commit), and then commit (push) to the remote repository, and SVN, compared to the equivalent of adding a layer of "cache", plus a layer of security. As shown in the following figure, there are some other details, some buttons that can be explored.



Switching between 3, two branches

The lower right corner of IntelliJ has git-related information, as shown in the following figure.


Git:xhf_buanch_test represents the current branch, in general our current percent is master. Local Branches: Represents a branch in the local repository, the branch is checkout from remote Branches, select the remote branch you want to download, right-select check out as new local branch, and select OK, A local branch will be added to the native branches.


But how do you switch between branches, which branch to commit to when you commit the code?

The current branch is what the default commits to which branch, so you want to modify which branch, you switch to the local branch, but there are some problems when the branch switch, in order to avoid these problems, it is best to ensure that the following points.

3.1 Before switching ctrl+k, make sure there are no files that are not submitted to the local repository

3.2 Update before switching, update this branch to the latest code.

Then select the branch in local branches to switch to the current branch. The following problems may occur, such as branch a_1 and branch a_2 two branches, when some files are added in a_1, but there is no commit, this time switch branches to a_2, a_2 also have uncommitted files in a_1.


When a merge is required to switch from the A_1 branch to the A_2 branch, we can choose the smart Merge, and when the smart merge does not solve the problem, we can manually merge,merge results of result, is to put these files on the branch you want to switch to, so the safest way is to choose the merge button.

Accept yours is the change that accepts A_1 branch, accept theirs is accepts a_2 branch of change.




4. New branch

Click on the Git box's new Branch, and then enter the name of your branch, according to the company's branch naming rules Oh. It will then automatically switch to the current branch and then push to the remote repository.

5. Synchronizing Remote branches

Someone may have created a new remote branch, but there is no remote branch in the local remote branches, so you need to right-click Git fetch.

6, the merge remote branch.

A merge B is to put the changes in a to the B branch, b merge A is to merge the changes in B into a, for example, the master branch changes on the branch FB_XHF, you can merge.

6.1 Go to the Master branch and update the latest Master Update.

6.2 Then go to FB_XHF, then select the Master branch in the local branches, select Merge, then merge the local master into the FB_XHF on the local repository and then choose Git Push, so the remote master Merge to FB_XHF, and will prompt: merged master to FB_XHF.


7. File Recovery

After local file modification, want to revert to the local git repository last commit, you can right-click git revert.

8, Cherry pick

Just like cherry picking, in the changes list, you can see the other branches of the dynamic, if you want to put a change in the current branch, you can right-click to select Cherry Pick, which is cherry picking.

9, if not careful should not merge when the merge, how to return to the last state.

In changes, select the latest submission, then right-click Reset Current Branch. Then the box is as follows


Select hard to return to the previous state, other options can be seen oh.


10. Color Change

Git does not add to git management when it is brown, the color after the add is green, after the submission of the color is normal color, after the change of color is blue.

11. How to delete some content that has been submitted to the local Git repository and remote repository.

You can use the git command:

11.1 git rm-r--cached file-or-foldername (ps: The file or directory that you want to delete, the local git library caches the files.) 11.2 git commit-m "removed folder from Repository" (PS: Submit to local) 11.3 Git push Origin master (PS: Commits the deletion to the remote branch.)

In IntelliJ, commit and push can be ctrl+k after the first step is executed.

12. IntelliJ Go unless the code is submitted

modified. Gitignore file and submit it to git. Changes as follows

         /target
         /.idea
         *.iml
         *.ipr
         *.iws
         . idea
         */*.log
         */target/
         *. Ds_store
         *.classpath
         *.settings
         *.project

Extension: git http://my.oschina.net/pengfeix/blog/191897?p=1#OSC_h3_3 http://www.51itong.net/ Git-commit-amend-commit-8551.html

PS: If you test, you can test on GitHub, which saves you from installing the GIT server locally.

Summary:

Git's extensive and profound also needs this princess many times research and the practice, also has many function wood to be useful. A summary of the basic use and pit, is a kind of a.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.