Git在Windows上:重命名文件后无法切换分支(仅更改大小写) [英] Git on windows: Can't switch branch after renaming a file (only changed case)

查看:1149
本文介绍了Git在Windows上:重命名文件后无法切换分支(仅更改大小写)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在windows上使用git,并在回购站中有一个文件,可以说foo.txt。
今天我想将这个文件重命名为Foo.txt(大写)。正如这个SO问题中所建议的那样,我使用 git mv -f foo.txt Foo.txt ,它产生了期望的结果。我继续将 commit 更改为我的repo。

编辑:我希望这是永久更改,并且仍然能够签出提交然后,在尝试切换分支时遇到错误:

<$ p $

> code>#我在分支1
git结账分支2
中止
错误:以下未跟踪的工作树文件将被结账覆盖:
Foo。 txt
请在移动或删除它们,然后才能切换分支机构。

经过一番探索之后,我发现我的 .git / config file有如下设置:

  [core] 
ignorecase = false
code>

将此更改为true似乎解决了问题,并允许我像常规一样在分支之间进行更改。



所以对此,我想知道:


  1. 这个设置是否有任何不利影响?它应该在Windows上一直如此吗?如果我与其他开发者合作并且他们没有为此设置相同的值,该怎么办?

  2. 是否有另一种重新命名文件而无需更改此设置的方法?

  3. 为什么这首先发生?当我提交更改时,git正确地确定该文件实际上已被重命名(没有删除一个文件,然后添加另一个文件)。那么,当我尝试切换分支时发生了什么?

谢谢!

解决方案

正如,将 core.ignorecase 设置为 true 是允许结账继续进行的有效方法。



但我更喜欢,如 / a>,到:




  • git add 你的情况下, git mv 可能已经将重命名的文件添加到索引中了) code>,保存索引

  • git checkout -b anotherBranch :因为索引很干净,所以应该可以工作

  • git stash pop ,如果您想要恢复该新索引的个案更改。

I'm working with git on windows, and I have a file in my repo, lets say "foo.txt". Today I wanted to rename this file to "Foo.txt" (uppercase). As suggested in this SO question, I used git mv -f foo.txt Foo.txt, which produced the desired result. I proceeded to commit the change to my repo.
EDIT: I would like this to be a permanent change, and still be able to checkout commit that predate this change.

However, after that I encountered an error upon trying to switch branch:

# I'm on branch1  
git checkout branch2  
Aborting  
error: The following untracked working tree files would be overwritten by checkout:  
Foo.txt  
Please move or remove them before you can switch branches.  

After some poking around I found that my .git/config file had the following setting:

[core]  
    ignorecase=false  

Changing this to true seems to fix the issue and allows me to change between branches as normal.

So regarding this, I would like to know:

  1. Is there any adverse effect of this setting? Should it always be true on windows? What if I'm working with other dev's and they don't have the same value set for this?
  2. Is there another way to rename the file without having to change this setting?
  3. Why does this happen in the first place? When I committed the change, git correctly identified that the file was in fact renamed (didn't delete one file and then add another). So what exactly happened when I tried to switch branches?

Thanks!

解决方案

As mentioned in "Unresolvable Git error: The following untracked working tree files would be overwritten by checkout", setting core.ignorecase to true is a valid way to allow the checkout to proceed.

But I would prefer, as in "GIT: The following untracked working tree files would be overwritten by checkout", to:

  • git add what I just modified (in your case, git mv might have already added the renamed file to the index)
  • git stash, saving the index
  • git checkout -b anotherBranch: this should work since the index is clean
  • git stash pop, if you want to restore the case change on that new index.

这篇关于Git在Windows上:重命名文件后无法切换分支(仅更改大小写)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆