【问题标题】:Renaming a file in Git [duplicate]在 Git 中重命名文件 [重复]
【发布时间】:2015-07-16 16:40:14
【问题描述】:

我在 Git 中有一个名为 100_Test_Customer_Team_abc.txt 的文件,它已被推送到远程存储库。我的名字弄错了——团队应该是大写字母,所以我想把它重命名为100_Test_Customer_Team_ABC.txt

我用过:

git mv 100_Test_Customer_Team_abc.txt 100_Test_Customer_Team_ABC.txt

但我收到以下错误:

致命:目的地存在

如何重命名?

【问题讨论】:

  • 文件系统是否区分大小写?
  • 重置头部并再次添加文件
  • Windows 操作系统
  • git mv 100_Test_Customer_Team_abc.txt tmp && git mv tmp 100_Test_Customer_Team_ABC.txt,也许吧。

标签: git


【解决方案1】:

你可以试试这个解决方案:

 git mv --force 100_Test_Customer_Team_abc.txt 100_Test_Customer_Team_ABC.txt

【讨论】:

    【解决方案2】:

    使用 mv 命令移动它:

    mv 100_Test_Customer_Team_abc.txt 100_Test_Customer_Team_ABC.txt
    

    由于您使用的是Windows,您只需通过Windows Explorer重命名文件即可。

    然后将所有更改添加为跟踪更改:git add -A。然后你会看到 Git 在git status 中跟踪删除/添加的重命名

    现在您可以简单地git commit -m 'Renamed file' 并推送到远程。

    【讨论】:

      猜你喜欢
      • 2015-08-15
      • 2011-04-24
      • 2011-12-07
      • 2016-04-15
      • 2011-02-08
      • 2011-02-11
      • 1970-01-01
      相关资源
      最近更新 更多