如何在本地创建分支冲突并合并分支

1. 项目实战中如何创建代码冲突

以下命令全部在项目根目录的dos命令窗口下执行

  1. 去码云官网自己的项目仓库新建test-confilct分支

  2. 执行git fetch命令【 同步远程分支到本地

  3. 执行git branch -a 查看是否同步正常,如果正常

  4. 执行git checkout -b test-confilct origin/test-confilct检出分支

  5. 用张维龙修改的CheckItemController 文件【替换自己的文件

  6. 执行 git add .添加修改的内容

  7. 执行 git commit -m “张维龙修改内容”提交修改的内容

  8. 执行 git push -u origin test-confilct 命令 【推送到gitee仓库

  9. git checkout order切换到项目的order分支

  10. 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);
            }
        }
    }
    
    
  11. 执行 git add .添加修改的内容

  12. 执行 git commit -m “李传播修改内容”提交修改的内容

  13. 执行 git push -u origin order 命令 【推送到gitee仓库

  14. 执行 git merge test-confilct合并test-confilct分支的代码

2. 解决冲突、提交代码、重新合并、推送代码、完成。

  1. 自行解决,可以上网搜索。可以用idea解决,只要能解决就好。
  2. 实在没有思路解决不掉的话参考一下内容
    1. 以下命令全部在项目根目录的dos命令窗口下执行
    2. 对比冲突文件,确定最终内容
    3. 执行git add . 重新添加修改文件
    4. 执行**git commit -m “解决冲突” **
    5. 执行 git merge test-confilct合并test-confilct分支的代码
    6. 执行 git push -u origin master 【推送到远程gitee仓库 】
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值