Git principle will be introduced in chapter later, this time mainly say how IntelliJ how to operate git. IntelliJ has a good git interface, you can pull the code, pull the branch details, submit code to the local warehouse, submit code to the remote warehouse, you can merge the local branch, the merge remote branch, you can freely switch branches, can solve the conflict caused by the merge problem. In summary, you can complete the basic git operation, as detailed below.
1, update the code
Ctrl+t, the code for the remote warehouse is updated. (PS: The default update is branch default and using stash, you can look at other options OH)
2. Submit Code
Ctrl+k, if the local code does not change, will prompt, no changes detected (detected no change). If the local code changes, you can commit, and for Git to commit, first commit to the local warehouse (commit) and then submit (push) to the remote repository, which is equivalent to a layer of "caching", plus a layer of security, compared to SVN. As shown in the following figure, there are some other details, some buttons that can be explored.
switching between 3 and two branches
The lower-right corner of the IntelliJ has git-related information, as shown in the following figure.
Git:xhf_buanch_test represents the current branch, and in general, our current per cent is master. Local branches: Represents a branch in a native warehouse, where the local branch is checkout from the remote branches, select the distant branch you want to download, right-click the check out as new local branch, and select OK. A local branch is added to the branches.
But how to switch between branches, the submission of the code is submitted to which branch.
The current branch is what the default commit to is which branch, so want to modify which branch, switch to which branch of the local, but in the branch switch when there are some problems, in order to avoid these problems, it is best to ensure that the following points.
3.1 Before switching ctrl+k to ensure that no files are not submitted to the local warehouse
Update the 3.2 before switching to the latest code.
Then select the branch in the 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 to the a_1, but there is no commit, then switching branches to a_2, a_2 also have uncommitted files in a_1.
When there is sometimes a switch from the A_1 branch to the a_2 branch, you need to merge, we can select the smart Merge, and when the smart merge does not solve the problem, we can manually merge,merge 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 to accept changes in the A_1 branch, accept theirs is to accept changes in the A_2 branch.
4. New branch
Click on the Git box's new Branch, and then enter the name of your own 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, synchronous remote branch
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 on git fetch.
6, the merge remote branch.
A merge B is to put the changes in a on the B branch, b merge A is the change in B merge into a, such as the master branch of the changes on the branch FB_XHF, you can merge.
6.1 Go to the Master branch, and then update master for the latest update.
6.2 Go to the FB_XHF, then select the Master branch in the local branches, select Merge, and then merge the native master into the FB_XHF of the local warehouse, then select Git Push, so that the remote master Merge to FB_XHF and will prompt: merged master to FB_XHF.
7. File Recovery
After the local file is modified, you want to revert to the local git warehouse last commit, you can right-click on git revert.
8, Cherry pick
Like cherry picking, in the changes list, you can see other branches submitted by the dynamic, if you want to put a change in the current branch, you can choose cherry Pick, this is cherry picking.
9, if not careful should not merge when the merge, how to return to the last state.
Select the latest submission in changes and then right click Reset Current Branch to here. And then the bomb box is as follows
Select hard will return to the previous state, the other options, you can see OH.
10. Color Change
Git is brown when not added to git management, the color after add is green, after submitting the color is normal color, there is a modified color is blue.
11. How to delete some content that has been submitted to the local GIT warehouse and remote repository?
You can use the git command:
11.1 git rm-r--cached file-or-foldername (ps: Files to be deleted, local git library cache.) 11.2 git commit-m "removed folder from Repository" (PS: Commit to local) 11.3 Git push Origin master (PS: Commit the deletion to the remote branch.)
In IntelliJ you can ctrl+k commit and push after the first step is performed.
12, IntelliJ to go unless the code submitted
modified. Gitignore file and submit it to git. Modify as follows
/target
/.idea
*.iml
*.ipr
*.iws
. idea
*/*.log
*/target/
*. Ds_store
*.classpath
*.settings
*.project
Extensions: 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 tested, it can be tested on GitHub, which eliminates the local installation of Git server.
Summary:
Git's profound also needs the princess many times research and the practice, but also has many function wood to be useful. Summing up the basic use and pits, is a kind of a draw.