Domanda

In my git repository I've got a weird file in the staging area that's refusing to be reverted, removed, committed - basically I can't make it go away..

The file must be some ancient OS 9 file sitting there in the folder for years.

Couple days ago I've removed the file in the file system so now git is tracking the deletion of Iconr.

However, it's stuck there.

The error I'm getting via SourceTree (my git UI client) is

fatal: pathspec 'folder/Iconr' did not match any files

Any idea how to make git completely forget about that file?

È stato utile?

Soluzione 2

It is best to revert to the command line in order to have a more precise error message.

There you can try a git add -u, followed by a git commit, in order to register the deletion of that file in the repo.
See "git status says file is deleted but git rm says error: pathspec '…' did not match any files" as an example.

You can also preview what a git clean would give: git clean -d -x -n (as explained in "Why is there no “pathspec” when I try to remove a folder in Git?")

The other issue is when that file isn't tracked at all in your current branch, but is tracked in another branch. See that answer to check if that is the case.

Altri suggerimenti

The Icon^M-like files most likely are created by some external apps such as Folderol which are highlighting your folders.

You should either remove the app which is doing that, or ignore it in your .gitignore file, e.g.

printf "Icon\r\r" >> .gitignore

This is a shell command. Or add it as Icon?? or you can reproduce ^M special character by Control-V and hitting Enter.

Related: How to ignore Icon? in git

If you don't want to commit this change into your repository, alternatively add it into your global .gitignore or add it into .git/info/exclude.

See: Using Git / Ignoring files.

To remove the files it-self, try:

find . -type f -name 'Icon?' -print -delete

Or if they're the only one which are unstaged, run: git clean -f.

As a general workaround the .gitignore file can be edited to completely ignore the Icon\r files as described in this blog entry: Git Tip: Ignoring Icon\r in .gitignore

You can ignore the Icon? on any level of subfolders using wildcards:

// .gitignore
**/Icon?

Wildcards works since version 1.8.2 of git

What shows as "Iconr" in SourceTree is really Icon\r where \r is the hex value 0x0d.

The .gitignore filename pattern matching is limited when compared to POSIX regex. Regular expression patterns such as Icon\r and Icon\x0d did not work for me with SourceTree.

Simple Ignore: Adding Icon? pattern in the .gitignore file will work to have "Iconr" files ignored in SourceTree.

Caveat: Icon? uses ? which is a single character wildcard. So, files and folders like Icon\r, "icona", "icon3" and "Icons" will be ignored with an Icon? pattern. If needed, use file names "Icon01", "icon02", "iconaa" instead of "Icon1", "icon2", "icona" with this workaround to add such files to git.

Precise Ignore: The precise Icon\r filename can be ignored with a binhex editor.

In binhex editor, add 0a 49 63 6f 6e 0d 0d 0a in the .gitignore file. The extra 0as are linefeeds to bracket the Icon\r\r for later editing of an otherwise unix file.

Caveat: If using the precise value 49 63 6f 6e 0d, be careful to not replace \r with \n. In other words, do not edit .gitignore in a text editor set to auto-replace line separators with this approach.

Note: The Simple Ignore Icon? is convenient and sufficient for most use cases. Quit and restart SourceTree to see the changes take effect. macOS's git is case-insensitive by default.

Custom Folder/File Icons: An Icon\r file is created each time a custom icon is added to a folder or file. For example, the custom icon can be added via the "Get Info" window. Here is an example where the default system folder icon has been replaced with a custom folder icon:

"Get Info" window

The Icon\r file(s) can be removed manually via the file's/folder's "Get Info" window or by invoking a shell command to remove the Icon\r files, as noted in kenorb's answer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top