14

I'm working on OSX. In a particular repo, whenever I tab to autocomplete after typing a git command:

$ git diff [clicks tab...]

I now see a huge number of warnings:

warning: ignoring ref with broken name refs/Icon
warning: ignoring ref with broken name refs/heads/Icon
warning: ignoring ref with broken name refs/remotes/Icon
warning: ignoring ref with broken name refs/remotes/origin/Icon
warning: ignoring ref with broken name refs/tags/Icon

It's really annoying, and it means that I can't see the filenames I want to see.

How can I remove or suppress these warnings?

I have an entry for Icon? in my gitignore file. There is an Icon? file in the local directory.

For all the trigger-happy people about to click "duplicate": I've searched for other answers, I found this but I'm not sure how it relates to my situation. It may be that the underlying cause is the same, but it would benefit me and others to have an explanation of how to fix this problem.

Community
  • 1
  • 1
Richard
  • 62,943
  • 126
  • 334
  • 542
  • I wonder if this is a result of OSX case-insensitive file system. Do you have a conflict between Icon/icon ? You could try `git update-ref -d ` to nuke one of them – Andrew C Jan 25 '16 at 20:34
  • You don't have the same problem (which is interesting), but the solution in the linked question is the same: delete the offending files carefully, after backing up your repo. – Edward Thomson Jan 31 '16 at 14:11

2 Answers2

12

The Icon\r file is created by Mac OS when you change a folder's icon.

How can I remove or suppress these warnings?

You need to delete the offending files themselves.

I have an entry for Icon? in my gitignore file.

That makes no difference. A .gitignore works on the working directory; these files are inside the repository folder where Git stores its metadata. .gitignore does not apply there. Git is mistaking them as branch names.

To fix this problem, you may be able to remove the custom icon you gave your folder(s). But if not, you will need to remove the files from beneath the .git folder. You can do this in Finder (after turning on "Show Hidden Files") or from the command line:

rm .git/refs/Icon?

Make sure to backup your repository before attempting this as changing things in the .git folder can corrupt your repository.

Community
  • 1
  • 1
Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • I ran a script that basically put a file in every directory with a directory listing in it. I did this at the root and had to run this to fix it which essentially does the same thing as the above command, but faster if you automated your disaster like I did. `find .git/ -iname "my-directory-list.txt" -delete` – Josiah Oct 08 '19 at 17:11
0

I had this:

warning: ignoring ref with broken name refs/heads/main (DropboxUser's conflicted copy 2023-08-22)

From an accidental Dropbox access. Since the name contained spaces, git was busted. I wrapped the name in parentheses and this command worked to remove the duplicate branch:

git update-ref -d "refs/heads/main (DropboxUser's conflicted copy 2023-08-22)"
soundflix
  • 928
  • 9
  • 22