git解决冲突

本文介绍如何使用Git创建新分支,并解决工作区文件更改所带来的冲突。包括创建并切换分支、提交更改、解决冲突的过程及合并分支的图形展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前提

建立一个新分支

$ git switch -c feature1

修改本地的工作区test.md文件然后再次提交add到feature1分支
在这里插入图片描述

$ git add test.md
$ git commit -m "new simple"

现在,master分支和feature1分支各自都分别有新的提交,变成了这样:
在这里插入图片描述
利用status查看是否存在冲突

On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    t2.md
no changes added to commit (use "git add" and/or "git commit -a")

存在冲突重新提交然后删除需要删除的内容

$ git add test.md
$ git commit -m "conflict fixed"

查看分支合并图

$ git log --graph

* commit f04f5fc5a1f52b3c50ae5a27387a8dac6d90f71b (HEAD -> master, origin/master)
| Author: matthewchen123 <ccc6687939@163.com>
| Date:   Mon Jan 25 10:50:35 2021 +0800
|
|     need to delete
|
* commit babd4e26cf847f2759cbc97de993d625b5312d93
| Author: matthewchen123 <ccc6687939@163.com>
| Date:   Mon Jan 25 10:41:28 2021 +0800
|
|     have a wrong word
|
* commit 6a9e57ac7f840f5674d641d09db914e117afaad6
| Author: matthewchen123 <ccc6687939@163.com>
| Date:   Sun Jan 24 20:26:58 2021 +0800
|
|     the third
|
* commit cf0cf78038378cc124e8b5ff1ed4da28a0c1445f
  Author: matthewchen123 <ccc6687939@163.com>
  Date:   Sun Jan 24 16:03:44 2021 +0800
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值