Use of Git in IDEA

Use of Git in IDEA

At work, multiple people use version control software for collaborative development. Common application scenarios are summarized as follows:

Suppose there are two people in the group, the group leader Xiao Zhang and the group member Xiao Yuan

Scenario 1: Xiao Zhang creates a project and submits it to the remote Git repository

Scenario 2: Xiaoyuan obtains the project source code from the remote Git repository

Scenario 3: Xiaoyuan modified some source code and submitted it to the remote warehouse

Scenario 4: Xiao Zhang gets Xiao Yuan's submission from the remote warehouse

Scenario 5: Xiaoyuan accepts the task of a new feature, creates a branch and develops on the branch

Scenario 6: Xiaoyuan submits the branch to the remote Git repository

Scenario 7: Xiao Zhang gets the branch submitted by Xiao Yuan

Scenario 8: Xiao Zhang merges the branch into the trunk

 

Let's take a look at the corresponding operations of the above scenarios in IDEA.

Scenario 1: Xiao Zhang creates a project and submits it to the remote Git repository

Create a project, select VCS -> Import into Version Control -> Create Git Repository

Next, specify the location of the local warehouse, which can be specified according to personal habits. For example, the project source code is selected in the same directory here.

After clicking OK, the local warehouse is created. Note that this is only local. Next, add the project source code to the local repository.

The following figure shows the operations corresponding to the three commit-related commands of Git. The Add command adds files from the IDE's working directory to the stage area of ​​the local warehouse. The Commit command submits the temporary files in the stage area to the warehouse of the current branch, and Clear the stage area. The push command synchronizes the commits of the local repository to the remote repository.

The operation has been simplified to a certain extent in IDEA, and Commit and Push can be completed in one step.

For specific operations, right-click on the project and select the Git menu

Because it is the first submission, you need to specify the address of the remote warehouse before Push. As shown in the figure below, after clicking Define remote, enter the remote warehouse address in the pop-up window.

Scenario 2: Xiaoyuan obtains the project source code from the remote Git repository

That is to clone the project, the operation is as follows:

Enter the remote warehouse address filled in when Xiaozhang Push

Next, follow the wizard to clone the project from the remote repository to the local repository and IDE workspace.

Scenario 3: Xiaoyuan modified some source code and submitted it to the remote warehouse

This operation is basically the same as the first submission process, namely Add -> Commit -> Push. Please refer to scenario 1

Scenario 4: Xiao Zhang gets Xiao Yuan's submission from the remote warehouse

There are two commands for getting updates: Fetch and Pull. Fetch downloads files from a remote repository to the local origin/master, and then you can manually compare and modify them to decide whether to merge them into the local master library. Pull is a direct download and merge. If each member is working on a specification that is updated before modification, the Pull method can be used directly to simplify the operation.

Scenario 5: Xiaoyuan accepts the task of a new feature, creates a branch and develops on the branch

Building a branch is also a common operation, such as temporarily modifying bugs, developing functions that are not sure whether to be added, etc., you can create a branch, and then wait for the right time to merge into the trunk.

The creation process is as follows:

Select New Branch and enter a branch name

After the creation is complete, pay attention to the lower right corner of IDEA, as shown in the figure below, Git: wangpangzi_branch indicates that it has automatically switched to the wangpangzi_branch branch, and the current work is on this branch.

After clicking, a small window will pop up. There are other available local branch options in Local Branches. After clicking, select Checkout to switch the currently working branch (see Scenario 7 to switch other branches).

As shown below, click Checkout

Note that the branch created here is only in the local warehouse. If you want the group leader Xiao Zhang to get this branch, you need to submit it to the remote warehouse.

Scenario 6: Xiaoyuan submits the branch to the remote Git repository

Switch to the newly created branch and use the Push function

Scenario 7: Xiao Zhang gets the branch submitted by Xiao Yuan

Use the Pull function to open the update window, click the refresh button behind the Remote column, and a new branch will be refreshed in the Branches to merge column. I don't want to do a merge here, so don't select any branches, just click the Pull button to complete the operation.

After the update, click on the lower right corner, and you can see that there is a new branch in the Remote Branches area. After clicking, select Checkout as new local branch in the pop-up submenu to create the branch in the local warehouse. After completion, the option of the branch will also appear in the Local Branches area. You can click the above method and select Checkout to switch.

Scenario 8: Xiao Zhang merges the branch into the trunk

The development of the new function was completed and the experience was very good. The project team decided to merge the function into the trunk.

Switch to the master branch and select Merge Changes

Select the branch you want to merge and click Merge to finish

Category: idea
0
0


currentDiggType = 0;

« Previous: Using gitlab
» Next: The list box on the left of powerdesigner is missing, how to get it out
    </div>
    <div class="postDesc">posted @ <span id="post-date">2018-03-14 15:16</span> <a href="http://www.cnblogs.com/javabg/">关键步就几步</a> 阅读(<span id="post_view_count">62</span>) 评论(<span id="post_comment_count">0</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=8567790" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(8567790);return false;">收藏</a></div>
</div>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324578176&siteId=291194637