问题描述

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. ZOJ - 3870-Team Formation二进制,位运算

    传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3870 题意:找出一个数列中的两个数,所有通过异或和使得结果同时大于 ...

  2. poj 2912 Rochambeau(枚举+带权并查集)

    题目链接:http://poj.org/problem?id=2912 题意:多个人玩石头剪刀布分成3组和一个裁判,每一组提前选定了自己出哪个手势,裁判可以随意出什么手势,问是否能够从给出的一系列石头 ...

  3. Educational Codeforces Round 68 Editorial

    题目链接:http://codeforces.com/contest/1194                                            A.Remove a Progre ...

  4. 如何配置nginx和tomcat实现反向代理?

    什么是反向代理         通常的代理服务器,只用于代理内部网络对Internet的连接请求,客户机必须指定代理服务器,并将本来要直接发送到Web服务器上的http请求发送到代理服务器中由代理服务 ...

  5. 【Offer】[10-1] 【斐波那契数列】

    题目描述 思路分析 Java代码 代码链接 题目描述  大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项(从0开始,第0项为0). 思路分析 递归的思路,会出现很多重复的 ...

  6. Linux基础_网站权限规划

    Linux系统默认的权限: 对于文件来说, 默认的权限: rw-r--r-- 644 对于目录来说:rwxr-xr-x  755 网站比较安全的权限: 网址程序存放在/app/blog 目录下面. 1 ...

  7. Appium+python自动化(三十六)- 士兵突击许三多 - 多个appium服务启动,多个设备启动,多进程并发启动设备-并发测试 - 上(超详解)

    简介 前面课程只是启动了单个appium服务,只能控制单台设备.如果需要针对多台设备测试那么该如何处理?而且发现群里的小伙伴们也在时不时地在讨论这个问题,想知道怎么实现的,于是宏哥就决定写一片这样的文 ...

  8. Redis的最常被问到知识点总结

    1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据库,很像memcached,整个数据库 ...

  9. kafka topic消息分配partition规则(Java源码)

    我们知道Kafka 的消息通过topic进行分类.topic可以被分为若干个partition来存储消息.消息以追加的方式写入partition,然后以先入先出的顺序读取. 下面是topic和part ...

  10. get和post请求方式的区别

    1.用途方面: get是向服务器请求数据,post是向服务器发送数据. 2.大小方面: get发送数据上有大小限制,post理想上无大小限制,实际上有限制. 3.安全方面: get请求的数据会显示在地 ...