I love Java Series --- [use] the idea in Git

1, arranged in the Idea of ​​Git

After installing IntelliJ IDEA, if Git installed in the default path, then the idea will automatically find the git location, if you change the mounting position of Git you need to manually configure the path under the Git. Select File → Settings to open the Settings window, find the git option under Version Control:

 

Click the Test button, the successful implementation of now, the configuration is complete

 

2, the operation in the Idea of ​​Git

2.1, initialize the remote repository project leader [operation]
  • Creating a remote repository project

  • Initialization and pushed to a remote warehouse

    The main initialization file is ignored and project initialization code, and pushed to the remote repository

    1. clone a remote repository to local

      • Local disk selected a folder, this is done using the git command

      • After completion clone, shown in FIG.

    2. Switch to the development branch

      • View current branch

      • The detection branch develop, and determine the development branch

    3. Add to ignore files

    4. The project initialization code into git repository

    5. By git add command completion, submission, push

2.2, create a local warehouse (not recommended)

Create a local repository locally and then associate with the remote repository, operate in this manner is not recommended.

 

2.3, clone remote repository to a local (recommended)
  1. Local disk selected a folder, use the git clone command to complete the operation.

 

  1. Switch to the development branch

     

 

2.4, open the clone of a local warehouse project

 

 

2.5, local warehouses normal operation
  1. New file

    For example, add a Java file in a package, as shown:

     

    Check to add new files, automatically added to the staging area, the new file automatically turn green

  2. Edit the file

    For example the content file existing one packet, as shown:

     

    Normal editing files, the default on the work area, if you need to add to the staging area, select the file, right-click menu, select the git-Add

  3. Before you reset the file to modify

    For example, the revision of a file, you need to reset to the state before modifying the file, select the file, right-click menu, select the git-reset

     

    After the reset, the file is automatically color disappears, indicating that it has reset to the state before the modification.

     

  4. Submitted to the local repository

    • Submit the current file

     

    • Submitting multiple files

       

    • Add comments and submit

     

     

    • Submit completed

       

2.6, pushed to the remote repository

Push operation:

  1. Add the contents of the work area to the staging area;

  2. Submit the staging area to the current branch;

  3. Pull the corresponding branch of a remote repository, if there is a conflict, to resolve the conflict and submit save

  4. Push the current branch to a remote repository

1, the corresponding branch pull remote repository

 

 

 

2, resolve merge conflicts

如果从远程仓库拉取的代码中,同一文件在本地仓库也修改了,需要解决合并冲突,比如如图所示:

 

解决冲突(根据业务情况,进行代码合并,并删除冲突提示)

 

提交合并冲突

 

推送当前版本到远程仓库

 

2.7、合并版本并推送到远程

如果当前版本需要发布,需要把develop合并到master版本

步骤:

1、切换到需要合并的版本,比如master

 

2、执行合并操作,使用当前版本合并其他版本到当前,比如master合并developer

 

3、合并完成,推送到远程仓库

 

2.8、创建分支

假如线上发生问题,需要解决线上问题,需要在master创建bugfix分支,解决线上问题。

2.9、切换分支

切换分支,只需要选中分支,然后选择checkout,就可以切换分支

 

2.10、版本比较

对代码修改后,可以点击对比按钮,对比差异

 

3.场景分析

基于实战模式,我们做一个综合练习

当前的开发环境如下,我们每个人都对这个项目已经开发一段时间,接下来我们要切换成团队开发模式。

也就是我们由一个团队来完成这个项目实战的内容。团队有组长和若干组员组成(组长就是开发中的项目经理)。

所有操作都在idea中完成。

练习场景如下:

1、由组长,基于本项目创建本地仓库;创建远程仓库,推送项目到远程仓库。(真实环境:项目经理创建空的项目推送,然后逐步添加内容,提交并推送)

2、每一位组员从远程仓库克隆项目到idea中,这样每位同学在自己电脑上就有了一个工作副本,可以正式的开始开发了。我们模拟两个组员(组员A、组员B),克隆两个工作区。

3、组员A修改工作区,添加到暂存区,提交到本地仓库。如果需要分享代码给另一个组员,推送到远程仓库。组员B可以直接从远程仓库获取代码,组员B可以获取组员A推送的代码。

4、组员A和组员B对同一个文件进行修改,提交代码到本地,这时需要分享代码给其他组员;组员A推送代码到远程仓库;组员B也推送代码到远程仓库,由于两位组员修改了同一个文件,推送失败。

解决方法:需要先获取远程仓库的代码到本地仓库,编辑冲突,提交并推送代码。

5、组员A接到组长命令,要对某功能进行重大的实验性调整;

操作思路:创建分支B1, 切换到B1分支,在B1分支上进行代码调整。B1分支达到了预期的目标,可以合并到原来的主干上;B1分支没有达到预期的目标,可以继续调整,也可以直接删除分支,切换到主分支继续开发。如果其他组员对主干上代码进行过调整,在合并时会产生冲突,需先解决冲突,再提交并推送。

Guess you like

Origin www.cnblogs.com/hujunwei/p/11279436.html