问题描述

Windows 或者 macOS 操作系统中,文件名是不区分大小写的。对于已经提交到仓库中的文件修改文件名的大小写,然后又用 git rm 命令将老文件从 Git 仓库删除掉,并保存下新的文件,这个时候,再进行切换分支的操作,就会出现这个提示:

复现

# 新建测试文件夹并切换到这个文件夹下面
mkdir test-checkout-error && cd test-checkout-error
# 新建空 Git 仓库
git init
# 新建测试文件 user.php
touch user.php
# 暂存新增文件
git add .
# 发现文件名大小写错误,进行修正
mv user.php User.php
# 再次暂存新增文件
git add .
# 提交到仓库
git commit -m "add user.php and User.php"
# 在当前分支基础上新建分支 dev
git checkout -b dev
# 删除索引中的 user.php
git rm --cached user.php
# 提交到仓库
git commit -m "delete user.php"
# 切换分支,报错
git checkout master error: The following untracked working tree files would be overwritten by checkout:
user.php
Please move or remove them before you can switch branches.
Aborting

分析

由于 Windows 或者 macOS 系统对于文件名是不区分大小写的,如果在 Git 仓库中应用了 ignorecase 的缺少配置 false,那么 Git 会区分文件名的大小写。

解决

在当前项目目录下执行

git config core.ignorecase true

然后再切换分支,进行分支合并等操作之后,再执行

git config --unset core.ignorecase

删除刚才的配置操作。

参考链接:git - The following untracked working tree files would be overwritten by checkout - Stack Overflow

git checkout 提示 “error: The following untracked working tree files would be overwritten by checkout” 解决的更多相关文章

  1. git解决error: The following untracked working tree files would be overwritten by checkout

    在IDEA中进行分支切换时,出现如此错误,导致无法正常切换:error: The following untracked working tree files would be overwritten ...

  2. Git错误:error: The following untracked working tree files would be overwritten by merge:

    [andy@localhost weixin_robot]$ git pull Updating d652d1c..fa05549 error: The following untracked wor ...

  3. Error pulling origin: error: The following untracked working tree files would be overwritten by...

    git在pull时,出现这样的错误的时候,可能非常多人进进行stash.相关stash的请看:Error pulling origin: error: Your local changes to th ...

  4. Some untracked working tree files would be overwritten by checkout. Please move or remove them before you can checkout. View them

    Some untracked working tree files would be overwritten by checkout. Please move or remove them befor ...

  5. git pull 错误:The following untracked working tree files would be overwritten by merge

    错误描述: $ git pull origin alphaFrom https://github.com/shirley-wu/HeartTrace * branch            alpha ...

  6. 错误 error: The following untracked working tree files would be overwritten by merge:README.md

    问题类型 相信很多小伙伴在创建新的git仓库后,会选上添加README.md文件,开始我也没太在意,应该也没有什么问题. 但是当我通过git添加远程仓库,给这个仓库上传代码时,出现了如下问题:erro ...

  7. git更新代码报错,error: The following untracked working tree files would be overwritten by ch

    git忽略大小写导致的, git config --add core.ignorecase true

  8. git clean解决 GIT error: The following untracked working tree files would be overwritten

    git clean用法:https://www.cnblogs.com/lsgxeva/p/8540476.html :

  9. The following untracked working tree files would be overwritten by merge

    git pull的时候遇到这样的问题: The following untracked working tree files would be overwritten by merge balabal ...

随机推荐

  1. lightoj 1140 - How Many Zeroes?(数位dp)

    Jimmy writes down the decimal representations of all natural numbers between and including m and n, ...

  2. 一台Linux服务器可以负载多少个连接?

    首先我们来看如何标识一个TCP连接?系统是通过一个四元组来识别,(src_ip,src_port,dst_ip,dst_port)即源IP.源端口.目标IP.目标端口.比如我们有一台服务192.168 ...

  3. 调度系统Airflow的第一个DAG

    Airflow的第一个DAG 考虑了很久,要不要记录airflow相关的东西, 应该怎么记录. 官方文档已经有比较详细的介绍了,还有各种博客,我需要有一份自己的笔记吗? 答案就从本文开始了. 本文将从 ...

  4. Junit测试Controller(MockMVC使用),以及传输@RequestBody数据解决办法

    转自:http://www.importnew.com/21153.html 一.单元测试的目的 简单来说就是在我们增加或者改动一些代码以后对所有逻辑的一个检测,尤其是在我们后期修改后(不论是增加新功 ...

  5. 阿里短信封装SDK TP3.2

    1.阿里短信接口需要企业认证: 2.短信需要短信模板 <?php /** * 阿里云短信验证码发送类 * @param string $accessKeyId key * @param stri ...

  6. 洛谷 P1980【计数问题】 题解(1)

    鉴于数据最高只有七位数,通过判断数位,逐位判断即可完成本题. (运行很快,打得手疼) //Stand up for the faith!#include<bits/stdc++.h> us ...

  7. spring data jpa介绍

    首先了解JPA是什么? JPA(JavaPersistence API)是Sun官方提出的Java持久化规范.它为Java开发人员提供了一种对象/关联映射工具来管理Java应用中的关系数据.他的出现主 ...

  8. 判断是手机端还是PC短访问

    第一种:判断是手机访问还是PC访问 <script> function browserRedirect() { var sUserAgent = navigator.userAgent.t ...

  9. 让你的AI模型尽可能的靠近数据源

    来源:Redislabs作者:Pieter Cailliau.LucaAntiga翻译:Kevin (公众号:中间件小哥) 简介 今天我们发布了一个 RedisAI 的预览版本,预集成了[tensor ...

  10. Thinkphp5.0 仿百度糯米 开发多商家 电商平台(完整版)

    目录第1章 课程简介第2章 需求分析第3章 快速掌握thinkphp5第4章 任性的TP5模块第5章 生活服务分类管理模块第6章 百度地图应用封装第7章 打造属于TP5自己的发送邮件服务第8章 商户模 ...