git mv 并且只更改目录的大小写 [英] git mv and only change case of directory

查看:23
本文介绍了git mv 并且只更改目录的大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我发现了类似的问题 我没有找到问题的答案

While I found similar question I didn't find an answer to my problem

当我尝试通过 git mv FOO foo 将目录从 FOO 重命名为 foo 时,我得到

When I try to rename the directory from FOO to foo via git mv FOO foo I get

fatal: renaming 'FOO' failed: Invalid argument

好的.所以我尝试 git mv FOO foo2 &&git mv foo2 foo

但是当我尝试通过 git commit . 提交时,我得到

But when I try to commit via git commit . I get

# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
# foo
nothing added to commit but untracked files present (use "git add" to track)

当我通过 git add foo 添加目录时,没有任何变化,git commit . 再次给我同样的信息.

When I add the directory via git add foo nothing changes and git commit . gives me the same message again.

我做错了什么?我以为我使用的是区分大小写的系统 (OSX),为什么我不能简单地重命名目录?

What am I doing wrong? I thought I'm using a case-sensitive system (OSX) why can't I simply rename the directory?

推荐答案

您处于不区分大小写的环境中.此外,在没有 -A 的情况下添加将不会处理 Git 理解的 mv 的删除端.警告!确保执行此操作时没有其他更改或未跟踪的文件,否则它们将作为此更改的一部分提交! git stash -u 首先,执行此操作,然后 git隐藏弹出之后.继续:要解决此问题,请执行以下操作:

You are in a case insensitive environment. Further, adding without the -A will not take care of the remove side of the mv as Git understands it. Warning! Ensure that no other changes or untracked files are around when you do this or they will get committed as part of this change! git stash -u first, do this and then git stash pop after. Continuing: To get around this, do the following:

mv foo foo2
git add -A
git commit -m "renaming"
mv foo2 FOO
git add -A
git commit --amend -m "renamed foo to FOO"

这是更改工作目录、提交然后折叠 2 个提交的详细方法.您可以只移动索引中的文件,但是对于 git 的新手来说,它可能不够明确地说明正在发生的事情.较短的版本是

That's the drawn out way of changing the working directory, committing and then collapsing the 2 commits. You can just move the file in the index, but to someone that is new to git, it may not be explicit enough as to what is happening. The shorter version is

git mv foo foo2
git mv foo2 FOO
git commit -m "changed case of dir"

正如其中一条评论中所建议的,您还可以执行交互式变基(git rebase -i HEAD~5 如果在 5 次提交前引入了错误的案例)来修复那里的案例,而不是有错误的案例出现在历史的任何地方.如果你这样做,你必须小心,因为从那时起提交的哈希值会有所不同,其他人将不得不重新设置或重新合并他们的工作与最近的分支.

As suggested in one of the comments, you can also do an interactive rebase (git rebase -i HEAD~5 if the wrong case was introduced 5 commits ago) to fix the case there and not have the wrong case appear anywhere in the history at all. You have to be careful if you do this as the commit hashes from then on will be different and others will have to rebase or re-merge their work with that recent past of the branch.

这与更正文件名有关:git不区分大小写吗?

这篇关于git mv 并且只更改目录的大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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