Home > Mobile >  git staged commit with invalid file name
git staged commit with invalid file name

Time:01-24

I was following a guide to ensure your JavaScript and CSS files were always refreshed when you updated them by adding ?v= to the filename. However Windows and git do not like this naming convention but I did manage to name the file audit.css to audit.css?v=1.0 using Cygwin. However as git doesn't like this filename it is stuck in changes to be committed. How can I removed the deleted change for this file? I have tried a few changes from other pages on stackoverflow but they have failed.

Cygwin$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        renamed:    audit.css?v=1.0 -> audit.css

Cygwin$ git restore --staged audit.css
Cygwin$ git status
On branch main
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    audit.css?v=1.0

Cygwin$ git restore --staged audit.css?v=1.0
error: invalid path 'audit.css?v=1.0'

Cygwin$ git reset 'audit.css?v=1.0'
error: invalid path 'audit.css?v=1.0'
fatal: make_cache_entry failed for path 'audit.css?v=1.0'

CodePudding user response:

The Windows OS is incompatible with that file naming convention.

Windows filenames cannot contain " * / : < > ? \ |. See this question.

  1. Easier: Move git operations into WSL. You can install it thru the Microsoft Store, IIRC it's just called "Ubuntu".

WSL doesn't have the same filename restrictions that Windows does. WSL accomplishes this by recording the Linux filename elsewhere, allowing Linux to "think" it has gotten away with adding Windows-restricted characters to filenames.

  1. Harder: Install Docker Desktop for Windows and use that for git operations.

This might not work since if the software reading/writing to the files still probably needs to run on Windows (such as an IDE), the same filename restrictions apply.

  1. Do away with the ?v= filename suffixes.

This smells like it's probably a misapplication of version control. The ?v=... convention to me looks like a string you'd put in your HTML to defeat the cache via URL parameters. It would probably be better to have the HTML contain the ?v=... strings, and let them be ignored by the web server.

CodePudding user response:

I don't have a test system, but you can be more heavy-handed with your removal of local changes

BEWARE both of these will throw away state, so take caution with any other parallel changes you'd like to keep

Discard local changes

git checkout -- .  # <-- note .

Discard any changes to HEAD

git reset --hard

CodePudding user response:

Since you didnt commit anything to remote branch (ie github), you can just roll back your changes like this

git reset --hard HEAD

what that will do is remove all your changes to the last time you pushed up into your remote repo (ie your last git push)


The other way is you could just change your file through file explorer. If you open your files and see it, right click, rename to new name. However this might not work because you changed the file extension previously to '.css?v=1.0' and that might have corrupted your file.

  • Rule of thumb, extensions are a way computers know what type of file it is and you shouldnt change anything after the '.'
  • Another rule is dont name files with special characters or spaces. It causes a lot of problems with paths and compatibility issues across apps

The other other way is just delete the file directly and start that file from scratch again. you can remove the file with file explorer or use this command in command line

go to the location of the file

rm audit.css?v=1.0

CodePudding user response:

You misunderstood the guide.

It's telling you to add that to your url, at the end of the filename. The filename should still be audit.css.

In all text processing there's a little dance going on. It's been carefully orchestrated and tweaked over ... wow, over literal generations now, to be as unintrusive as possible, but you've just tripped over one of the entries to the rabbit warren.

In case you're feeling motivated, here's the start of the particular rabbit hole you fell in to. Search for a question mark or just start reading. That document tells you how your url is parsed and some of what's supposed to be done with the pieces.

The referenced file is still intended to be audit.css; web caching between your server and whatever browser is supposed to remember the entire cached url but your server's supposed to interpret the ? and what follows as a query with parameters, which can sometimes be and here is supposed to be ignored. So if you change the ?v= query the caches will see it doesn't match what they've got cached and pass the request along to your server, which if you want to keep your sanity in this use you've set up to ignore that particular query.

  •  Tags:  
  • git
  • Related