Git:文件重命名 [英] Git: File Rename

查看:191
本文介绍了Git:文件重命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个文件夹从 Frameworks 重命名为 frameworks ,但git不会让我添加新的小写名称。我猜这对待文件名不区分大小写,是不是?

A git add frameworks / -f 没有帮助

解决方案

您可以尝试: > git mv -f foo.txt Foo.txt(注意:这是不再需要,因为git 2.0.1

  • 在配置文件中将 ignorecase 设置为false。
  • li>





    但是case(在Windows上)的问题在 msysgit issue 228 (再次说明:这应该是现在 - 2014年6月 - 使用git 2.0.1


    总是有一个选项可以在配置文件中将 ignorecase 设置为false,这将迫使Unix像Git语义一样在NTFS之上。

    Git支持这种行为但它不是默认值 - 从NTFS的角度来看 a.txt
    A.txt 是同样的事情 - 所以Git会尽可能保留这个功能,因为大多数用户都会期望这样做。



    作为一个更好的解决方法,您可以

      git mv foo.txt foo.txt。 tmp&& git mv foo.txt.tmp Foo.txt 

    ,这也改变了存储文件的情况。


    这篇博客文章在rebase期间演示MacOs上的相同问题 b
    $ b


    Mac OS X文件系统是它们不区分大小写。 FFFFFF.gif ffffff.gif



    如果您从文件系统删除文件,而不是从Git索引中删除,请注意,您可以合并有问题的分支,并让它恢复文件,就好像没有任何事情发生一样。



    步骤很简单:

      $ rm file / in /question.gif 
    $ git merge trunk







    无论如何,记住什么是git mv代表 a>:

      mv oldname newname 
    git add newname
    git rm oldname
    code>

    ,所以如果 newname oldname code>冲突,你需要使它们不同(即使它只是一小段时间),因此 git mv foo.txt foo.txt.tmp&& git mv foo.txt.tmp Foo.txt


    I wanted to rename a folder from "Frameworks" to "frameworks", but git would not let me add the new lowercase name. I guess it treats filenames case insensitive, does it?

    A git add frameworks/ -f didn't help

    解决方案

    You can try:


    But the issue of case (on Windows for instance) is described in the msysgit issue 228 (again: this should now -- June 2014 -- work with git 2.0.1)

    there is always an option to set ignorecase to false in the config file that will force Unix like Git semantics on top of NTFS.
    Git supports this behavior but it is not the default - from NTFS point of view a.txt and A.txt are the same thing - so Git tries to preserve that as most users would expect

    As a better workaround, you can

    git mv foo.txt foo.txt.tmp && git mv foo.txt.tmp Foo.txt
    

    , which also changes the case of the file as stored on disk.

    This blog post illustrates the same issue on MacOs during a rebase:

    The default on Mac OS X file systems is that they are case-insensitive. FFFFFF.gif is the same as ffffff.gif.

    If you delete the file in question, just from the file system, not from the Git index, mind you, you can merge the branch in question, and have it restore the file as if nothing happened.

    The steps are pretty simple:

    $ rm file/in/question.gif
    $ git merge trunk
    


    Anyhow, remember what git mv stands for:

    mv oldname newname
    git add newname
    git rm oldname
    

    , so if newname and oldname clash, you need to make them different (even if it is only for a short period of time), hence the git mv foo.txt foo.txt.tmp && git mv foo.txt.tmp Foo.txt

    这篇关于Git:文件重命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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