关于代码覆盖 or 冲突

关于代码覆盖 or 冲突

在使用git同步代码时,步骤一般为 commit -> pull -> push

那这个过程的意义何在呢?

  1. 首先是区分本地仓库 与 远程仓库,可以理解为本地git仓库和github仓库
  2. commit操作可以让本地仓库确定项目的修改内容
  3. pull可以对比本地仓库某分支与远程仓库某分支,在这个过程中可能会提示出现内容冲突的情况(远程仓库和本地仓库同时修改了代码),比如当本地README.md与远程README.md同时修改,出现如下error
       error: Your local changes to the following files would be overwritten by merge:
               README.md
       Please commit your changes or stash them before you merge.
       Aborting
  1. 此时需要决定采取哪个修改(本地or远程),决定好后,在本地修改代码。之后从新执行一遍git add . git commit -m 'update' , 此后从新进行pull操作,如果提示fatal: refusing to merge unrelated histories, pull操作添加参数--allow-unrelated-histories

  2. 类似情况,应变方法大同小异。像出现下面的error

       error: Pulling is not possible because you have unmerged files.
       hint: Fix them up in the work tree, and then use 'git add/rm <file>'
       hint: as appropriate to mark resolution and make a commit.
       fatal: Exiting because of an unresolved conflict.

这种出现本地冲突(conflict)的错误,一般都可以通过重复add -> commit -> pull的操作解决,主要是Git想确认你是否想修改,一旦push之后,就会将远程仓库对应分支改成本地仓库分支的代码,即修改远程仓库,所以这个error相当于一次警告提示

还有不懂可以看 https://www.cnblogs.com/xzybk/p/11326808.html

上面是强制pull, 强制push使用$ git push -u origin master -f

原文地址:https://www.cnblogs.com/friedCoder/p/12237906.html