git问题解决

1、如果系统中有一些配置文件在服务器上做了配置修改,然后后续开发又新添加一些配置项的时候,

在发布这个配置文件的时候,会发生代码冲突:

error: Your local changes to the following files would be overwritten by merge:
        protected/config/main.php
Please, commit your changes or stash them before you can merge.

你本地修改的将会被合并覆盖。要么提交、要么存储起来或者回退掉修改的内容,才能继续进行

  解决方案,按照提示来说,就是三种办法:

a、你先提交自己对文件的修改,再去拉代码

  1. git add . #修改放到暂存区 
  2. git commit -m '哥不服' #提交到本地仓库  
  3. git push #假设就一个远程分支,该省略的全省了

b、你先把自己修改的内容藏起来

  1. git stash #先把自己的修改都存储起来
  2.  git pull #拉新代码
  3.  git stash pop #再把存储的代码拿出来,在本地仓库自动合并

c、远程分支为准,自己在本地的修改不要了

  1. git reset --hard #放弃本地修改 
  2. git pull #拉远程分支代码

2、git .gitignore 文件 解决二进制文件冲突问题 

  .gitignore  主要是添加 忽略文件 。最近团队开发经常出现 

  UserInterfaceState.xcuserstate 冲突,打开发现是二进制文件 ,没法解决冲突。

  只好 rm -rf 之,次数多了真烦啦。

一劳永逸解决方案:

  1,找到 .gitignore 添加 UserInterfaceState.xcuserstate 不纳入版本管理

  2,移除git 已经跟踪的UserInterfaceState.xcuserstate  ,启用.gitignore 忽略对应文件

        1)、git rm --cached YourProjectFolderName.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate

         2)、git commit -m "Removed file that shouldn't be tracked"

         3)、git clean -f -d

 

3、git pull 报错

  error: Pulling is not possible because you have unmerged files.
  解决办法:
    1. git add -u
    2. git commit -m""
    3. git pull

  先将文件先存放到暂存区然后提交注释,再git pull不报错了
  这种报错一般是以为有冲突的文件,需要解决冲突或者合并文件,解决完或者合并之后需要重新提交,不限于pulling

原文地址:https://www.cnblogs.com/soft2018/p/10364472.html