zoukankan      html  css  js  c++  java
  • Eclipse+EGit的配置注意点, 以及解决Github多个本地仓库之间的冲突

    问题描述

    不同本地仓库(e.g. Repo1, Repo2)之间同时修改一个文件时, 出现文件无法merge的情况.

    具体表现为, 冲突(红色双向实心箭头)一直存在, 点pull没反应, 点push报错, 双击文件也没有出现merge提示("<<<<<<"这样的符号), 点"add to index", mark as merged等等 都没用. 手动merge或者overwrite, 也无法push回remote.

    原因:

    repo1和repo2同时修改一个文件e.g. README.MD

    repo1修改成AAA, commit+push到remote

    repo2修改成BBB, commit到本地.Fetch, 进入Sync Perspective. 冲突可见.

    此时, 正确操作应该是: repo2中选择冲突文件, 用merge tool来合并成最终版本.

    但如果操作人员不小心, 讲repo2中的冲突文件直接修改成CCC, 且不commit, 则会遇到上述问题. 导致pull(fetch+merge)不成, push不成, merge界面不出现的尴尬情形.

    在冲突文件较多时, 这个问题比较隐蔽, 容易造成困扰.

    根本原因:

    不通过merge tool或者pull(不推荐), 直接修改文件, 会导致repo2的staging和本地仓库不一致.

    此时, 该文件对repo2而言, staging, local repo, remote repo内容各不相同.

    commit之后使得本地所有文件一致. 可以重新开始fetch+merge.

    解决方法:

    在repo2中, 修改冲突文件, commit, 再次走正常merge步骤即可.

    题外话

    Eclipse中配置EGit - 具体参数意义 https://git-scm.com/docs/git-config

    1. 有防火墙的情况下记得设置http.proxy

    2. http.sslVerify设置为false避免push fetch时做http的ssl验证.

    3. core.autocrlf - 如果跨Windows(CRLF), Mac(CR)和Linux(LF)写代码, 需要注意这个换行符的问题. 设置如下(3个选项)  另有core.safecrlf可以做检查用.

    #添加文件到git仓库时, 视为text, 自动把crlf变lf. 取出的时候又把文件转成crlf.
    # x -> LF -> CRLF
    git config
    --global core.autocrlf true

    # x -> LF -> LF #添加时, crlf转lf, 取出文件的时候, 不做转换, 仍是lf. git config
    --global core.autocrlf input #不做转换, 原样进出
    # x -> x -> x git config
    --global core.autocrlf false
    #拒绝提交包含混合换行符的文件
    git config --global core.safecrlf true   
    
    #允许提交包含混合换行符的文件
    git config --global core.safecrlf false   
    
    #提交包含混合换行符的文件时给出警告
    git config --global core.safecrlf warn

    因此, 只在Windows系统下开发, 直接设false即可. 仓库中和workspace中的换行符都是CRLF.

    此外, 如果文件中包含中文字符且使用UTF-8编码, 也应该用false保证文件一致性. 转换过程可能导致问题.

    Windows+Linux/Mac开发: Windows下设置为true, Mac/Linux下设置为input. 

    这样Windows的Workspace中是CRLF (提交时会把CRLF转换成LF, 取出时会把LF转换成CRLF)仓库和Mac/Linux的Workspace下都是LF.

  • 相关阅读:
    批量新增百万条数据 十百万条数据
    sqlserver 组内排序
    EF ++属性会更新实体
    Entity Framework Core: A second operation started on this context before a previous operation completed
    abp Cannot access a disposed object. A common cause of this error is disposing
    abp xunit Can not register IHostingEnvironment. It should be a non-abstract class. If not, it should be registered before.”
    hangfire enqueued but not processing(hangfire 定时任务入队列但不执行)
    EF 更新实体 The instance of entity type 'BabyEvent' cannot be tracked because another instance
    datatable to entiy list 不支持可空类型和枚举类型
    webapi 设置不显示接口到swaggerUI
  • 原文地址:https://www.cnblogs.com/haibinyuan/p/5011503.html
Copyright © 2011-2022 走看看