简体   繁体   English

Mac OS上的Git区分大小写:无法锁定引用

[英]Git on MacOS case sensitivity: cannot lock ref

I believe a teammate had a feature branch named Fix/my-fix and then renamed it fix/my-fix , changing the case, and pushed it to our central repo. 我相信一个队友有一个名为Fix/my-fix的功能分支,然后将其重命名为fix/my-fix ,更改了大小写,并将其推送到我们的中央仓库中。

Now, every time I do a git pull , I see 现在,每次执行git pull

error: cannot lock ref 'refs/remotes/origin/fix/my-fix': is at addd9e22effc39t86eca875a1db74f4cc2d09747 but expected cec2dce30eb3a5tf370c3d3b39540f9d2e347020
 ! cec2dce30..addd9e22e  fix/my-fix                 -> origin/fix/my-fix  (unable to update local ref)

If I do a git remote prune origin or git fetch --all --prune , then it fixes the issue so I can do one successful pull but then the second time I pull I get the error again. 如果我执行git remote prune origingit fetch --all --prune ,那么它可以解决此问题,因此我可以一次成功拉出,但是第二次我再次拉出错误。 So essentially I have to prune before every pull. 因此,基本上,每次拉动之前我都必须prune

Is there any way I can solve this issue locally, without deleting his feature branches from our central git repo? 有什么办法可以在本地解决此问题,而无需从中央git存储库中删除其功能分支? I don't care about his branch at all, so an acceptable workaround would be to tell git to ignore it permanently somehow; 我根本不在乎他的分支,因此可以接受的解决方法是告诉git以某种方式永久忽略它。 I just need to be able to consistently pull without having to prune . 我只需要能够持续pull而不必prune

I've also tried 我也尝试过

git update-ref -d refs/remotes/origin/fix/my-fix

and

git gc --prune=now

and those similarly only solved the issue temporarily. 那些同样只能暂时解决问题。

I've read the background around case-sensitive filesystems in this article . 我已经阅读了本文中区分大小写的文件系统的背景知识。

Based on your description, the uppercase spelling version of the branch should not be returning (so that the one-time git fetch -p or git remote prune should have been a permanent solution). 根据您的描述,该分支的大写拼写版本应该返回(因此,一次性git fetch -pgit remote prune应该是永久解决方案)。 However, if it works once, you can just enable it as the default action for this one repository on your Mac: 但是,如果它可以运行一次,则可以将其作为Mac上该存储库的默认操作启用:

git config fetch.prune true

or for all of your repositories 1 on your Mac: 或Mac上所有存储库1

git config --global fetch.prune true

This is equivalent to making all git fetch commands be git fetch -p commands. 这等效于使所有git fetch命令成为git fetch -p命令。

(There's no particularly good reason not to run with fetch.prune set to true . I do this myself: I have my global configuration set this way.) (没有特别好的理由fetch.prune设置为true来运行。我自己这样做:我以这种方式设置了全局配置。)


1 Technically, this would be all repositories except any that locally override with fetch.prune=false . 1从技术上讲,这将是所有存储库, 除了那些使用fetch.prune=false在本地覆盖的存储库。 In general—there are some specific and important exceptions—things that you set with git config --global get overridden by anything you set with git config , because what Git does is: 通常,有一些特定且重要的例外情况,您使用git config --global设置的内容git config --global会被您使用git config设置的任何内容所覆盖,因为Git所做的是:

  • Read the system configuration file first, to get settings. 首先阅读系统配置文件,以获取设置。
  • Read your global configuration file for settings. 阅读全局配置文件进行设置。 Anything you set here that was already set is now overridden by your global setting. 您在此处设置的所有已设置内容现在都将被全局设置覆盖。
  • Read your repository's configuration file for settings. 阅读存储库的配置文件以获取设置。 Anything you set here that was already set is now overridden by the repository's setting. 您在此处设置的所有已设置内容现在都将被存储库的设置覆盖。
  • Apply any -c key=value arguments from the command line. 从命令行应用任何-c key=value参数。 Anything you set here that was already set is now overridden by the command-line setting. 您在此处设置的所有已设置内容现在都将被命令行设置覆盖。

This is particularly useful if you, eg, do consulting work: you can set your name and email address to your personal settings, then, for each repository on which you're doing consulting work, set your name and email address to whatever the job requires for that repository. 例如,在进行咨询工作时,这尤其有用:您可以将名称和电子邮件地址设置为个人设置,然后针对要进行咨询工作的每个存储库,将名称和电子邮件地址设置为任何工作该存储库所需。

Laziness >> Correctness here. 懒惰>>正确在这里。 Assuming the server now only has one case variant: 假设服务器现在只有一种情况:

  • Push your local branches. 推当地分支机构。
  • Blow away your repo (I suggest just renaming the directory so you can recover) 销毁您的存储库(我建议您仅重命名目录即可恢复)
  • Start again with a new git clone 从新的git clone重新开始

If you don't want to push everything to the server, you can push to a local bare repository with git init --bare . 如果您不想将所有内容推送到服务器,则可以使用git init --bare推送到本地裸存储库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM