Manu Manu - 3 months ago 22
Git Question

Git project has a folder with an unsupported invisible character

I have been working on a git project with a remote on Github. It contains several submodules.

When creating a submodule, my git client (Sourcetree) created a folder with an invisible character, which has been wreaking havoc. The folder has been pushed to Github, and I can't find a way to revert.

The submodule folder looks like it's named "cours-divers", but is displayed in Sourcetree as "cours020-divers", and shown as "cours?-divers" in Terminal.

Also, Sourcetree isn't able anymore to display the list of submodules.

What I attempted, after reading through related threads:

  • Simply deleting it. Unfortunately, Git cannot properly track this file so it doesn't get deleted. Error message:
    fatal: pathspec 'cours020-divers' did not match any files

  • Doing
    git reset --hard [revision]
    . This works fine for my local version, but the remote (Github) requires me to pull the changes. I would need to be able to reset the remote as well.

  • Doing
    git checkout [revision] .
    Seems to bring things back to normal, but the problematic file is still polluting the project.

Is there a way to "go back in time" in such a way that Git effectively forgets about that file, both locally and on the remote?


Finally, after some more trial and error, I found that this thread provides the answer: Resetting remote to a certain commit

git reset --hard <commit-hash>
git push -f origin master

Doing this does effectively push the project back in time, and gets rid of any reference of the offending file.