1. 项目实战中如何创建代码冲突
以下命令全部在项目根目录的dos命令窗口下执行
-
去码云官网自己的项目仓库新建test-confilct分支
-
执行git fetch命令【 同步远程分支到本地 】
-
执行
git branch -a
查看是否同步正常,如果正常 -
执行git checkout -b test-confilct origin/test-confilct 【检出分支】
-
用张维龙修改的CheckItemController 文件【替换自己的文件】
-
执行 git add . 【添加修改的内容】
-
执行 git commit -m “张维龙修改内容” 【提交修改的内容】
-
执行 git push -u origin test-confilct 命令 【推送到gitee仓库】
-
git checkout order 【切换到项目的order分支】
-
对 CheckItemController 文件做一下更改(随便改一点内容)CheckItemController内容如下:
package com.itheima.controller.backend; import com.itheima.common.constant.MessageConstant; import com.itheima.common.entity.PageResult; import com.itheima.common.entity.QueryPageBean; import com.itheima.common.entity.Result; import com.itheima.pojo.CheckItem; import com.itheima.service.CheckItemService; import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.List; /** * 检查项管理 */ @RestController @RequestMapping("/checkitem") public class CheckItemController { @Autowired private CheckItemService checkItemService; /** * 新增 * @param checkItem * @return */ @RequestMapping("/add") public Result add(@RequestBody CheckItem checkItem){ try{ checkItemService.add(checkItem);//发送请求 return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS); }catch (Exception e){ e.printStackTrace(); return new Result(false, MessageConstant.ADD_CHECKITEM_FAIL); } } /** * 分页查询 * @param queryPageBean * @return */ @RequestMapping("/findPage") public PageResult findPage(@RequestBody QueryPageBean queryPageBean){ return checkItemService.findPage(queryPageBean); } /** * 根据id删除检查项 * @param id * @return */ @RequestMapping("/delete") // @PreAuthorize("hasAuthority('CHECKITEM_DELETE')") public Result delete(Integer id){ try{ checkItemService.delete(id);//发送请求 return new Result(true, MessageConstant.DELETE_CHECKITEM_SUCCESS); }catch (Exception e){ String message = e.getMessage(); e.printStackTrace(); return new Result(false, message); } } /** * 根据id查询检查项 * @param id * @return */ @RequestMapping("/findById") public Result findById(Integer id){ try{ CheckItem checkItem = checkItemService.findById(id);//发送请求 return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem); }catch (Exception e){ e.printStackTrace(); return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL); } } /** * 编辑 * @param checkItem * @return */ @RequestMapping("/edit") public Result edit(@RequestBody CheckItem checkItem){ try{ checkItemService.edit(checkItem);//发送请求 return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS); }catch (Exception e){ e.printStackTrace(); return new Result(false, MessageConstant.EDIT_CHECKITEM_FAIL); } } /** * 查询所有检查项 * @return */ @RequestMapping("/findAll") public Result findAll(){ try{ List<CheckItem> list = checkItemService.findAll();//发送请求 return new Result(true, MessageConstant.QUERY_CHECKITEM_SUCCESS,list); }catch (Exception e){ e.printStackTrace(); return new Result(false, MessageConstant.QUERY_CHECKITEM_FAIL); } } /** * 根据检查组id查询关联的检查项id * @param checkgroupId * @return */ @RequestMapping("/findCheckItemIdsByCheckGroupId") public Result findCheckItemIdsByCheckGroupId(Integer checkgroupId){ try{ List<Integer> list = checkItemService.findCheckItemIdsByCheckGroupId(checkgroupId); return new Result(true,MessageConstant.QUERY_CHECKITEM_SUCCESS,list); }catch (Exception e){ e.printStackTrace(); return new Result(false,MessageConstant.QUERY_CHECKITEM_FAIL); } } }
-
执行 git add . 【添加修改的内容】
-
执行 git commit -m “李传播修改内容” 【提交修改的内容】
-
执行 git push -u origin order 命令 【推送到gitee仓库】
-
执行 git merge test-confilct【 合并test-confilct分支的代码】
2. 解决冲突、提交代码、重新合并、推送代码、完成。
- 自行解决,可以上网搜索。可以用idea解决,只要能解决就好。
- 实在没有思路解决不掉的话参考一下内容
- 以下命令全部在项目根目录的dos命令窗口下执行
- 对比冲突文件,确定最终内容
- 执行git add . 重新添加修改文件
- 执行**git commit -m “解决冲突” **
- 执行 git merge test-confilct【 合并test-confilct分支的代码】
- 执行 git push -u origin master 【推送到远程gitee仓库 】