• git冲突解决


    您是否有遇到类似下面的的git冲突提示、有的话、让我们一起来看看是怎么产生这样的问题的!
    Pull is not possible because you have unmerged files.
    Please, fix them up in the work tree, and then use 'git add/rm <file>'

    一、首先创建一个测试库、和测试clone库

    test $ mkdir repo && cd repo && git init && touch file && git add file && git commit -m "msg"
    repo $ cd .. && git clone repo repo_clone && cd repo_clone
    repo_clone $ echo "text2" >> file && git add file && git commit -m "msg" && cd ../repo
    repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone

    二、现在在repo_clone执行git pull就会报conflicts

    repo_clone $ git pull origin master
    remote: Counting objects: 5, done.
    remote: Total 3 (delta 0), reused 0 (delta 0)
    Unpacking objects: 100% (3/3), done.
    From /home/anshulgoyal/Desktop/test/test/repo
     * branch            master     -> FETCH_HEAD
       24d5b2e..1a1aa70  master     -> origin/master
    Auto-merging file
    CONFLICT (content): Merge conflict in file
    Automatic merge failed; fix conflicts and then commit the result.

    三、如果我们忽略这个冲突不去解决它、而远端origin还在执行commit

    repo_clone $ cd ../repo
    repo $ echo "text1" >> file && git add file && git commit -m "msg" && cd ../repo_clone

    四、此时我们再来执行clone库里面的git pull、就会得到我们遇到的问题。

    repo_clone $ git pull
    U   file
    Pull is not possible because you have unmerged files.
    Please, fix them up in the work tree, and then use 'git add/rm <file>'
    as appropriate to mark resolution, or use 'git commit -a'.

    五、此时我们执行git status就可以清晰的看到未处理的冲突问题。

    repo_clone $ git status
    On branch master
    Your branch and 'origin/master' have diverged,
    and have 1 and 1 different commit each, respectively.
      (use "git pull" to merge the remote branch into yours)
    
    You have unmerged paths.
      (fix conflicts and run "git commit")
    
    Unmerged paths:
      (use "git add <file>..." to mark resolution)
    
            both modified:      file

    六、所以要解决这个问题、我们就需要解决之前遇到的冲突而没有解决掉得问题。

    vi file 把里面的冲突解决掉、让后重新提交file

    repo_clone $ git add file && git commit -m "resolved merge conflicts"
    [master 39c3ba1] resolved merge conflicts

    问题解决。

  • 相关阅读:
    英文字母打字速度测试游戏代码
    JS写一个JS解释器
    JS中try.. catch..的用法
    使用HTML CSS和JavaScript创建图像动画
    6个强大的CSS选择器
    TypeScript 3.9稳定版本新增功能
    10个JavaScript代码片段,使你更加容易前端开发。
    BZOJ.3811.玛里苟斯(线性基)
    Bluestein's Algorithm
    AGC 002E.Candy Piles(博弈论)
  • 原文地址:https://www.cnblogs.com/miaoshiqian/p/4431580.html
Copyright © 2020-2023  润新知