### Godot version

4.x

### System information

Fedora 37, ubuntu:latest

### Issue description

When a repo with a Godot 4.x project is cloned and `godot --headless --export-release <NAME> <PATH>` is executed, it will fail to find GDScript classes (those not attached to any Scene or Resource but used as global resources).

Locally, it can be worked around by executing the Godot Editor once without using the `--headless` option, to let it create the `.godot` subdir. Therefore, the headless export depends on files in `.godot` which it cannot create by itself.

Precisely, if `.godot/global_script_class_cache.cfg` is added to SCM, the headless run with an otherwise empty `.godot` will succeed.

However, with Godot 4.x, a `.gitignore` file is added by default, which does ignore `.godot/`. In order to add `global_script_class_cache.cfg`, the `.gitignore` needs to be modified:

```gitignore
/.godot/**/*.*
!/.godot/global_script_class_cache.cfg
```

See https://github.com/itsas-taldea/moon/commit/d12a5ccd41f1ecc2308721cc12d83d603c1df4d2

I don't know what the solution would be:

- Should Godot regenerate the config file transparently without errors?
- Does that info need to be saved in the project file (which is checked in SCM) instead of in subdir `.godot`?

### Steps to reproduce

```sh
git clone https://github.com/itsas-taldea/moon
cd moon
git checkout -b test-bug bada535a
cd godot
# This will produce errors such as: 'SCRIPT ERROR: Parse Error: Identifier "Utils" not declared in the current scope.'
godot --headless --export-release Linux ./moon.linux

rm -rf .godot
# Open the project in Godot "normally", then close it.
# Now, it will not produce SCRIPT ERRORs:
godot --headless --export-release Linux ./moon.linux

# Let's copy the problematic config file for later use
cp .godot/global_script_class_cache.cfg ../

rm -rf .godot
# It will produce errors again
godot --headless --export-release Linux ./moon.linux

rm -rf .godot
mkdir .godot
mv ../global_script_class_cache.cfg .godot/
# It will succeed now
godot --headless --export-release Linux ./moon.linux
```

### Minimal reproduction project

See subdir in https://github.com/itsas-taldea/moon. Note that branch `main` includes `.godot/global_script_class_cache.cfg`. That needs to be removed in order to reproduce this issue.

See https://github.com/itsas-taldea/moon/actions/runs/4614444782/jobs/8157419040 and https://github.com/itsas-taldea/moon/actions/runs/4614591084/jobs/8157704125.

p_import_data->max_index = MAX(p_import_data->reimport_from + int(p_index), p_import_data->max_index);
	_reimport_file(p_import_data->reimport_files[p_import_data->reimport_from + p_index].path);
}
void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
	ERR_FAIL_COND_MSG(importing, "Attempted to call reimport_files() recursively, this is not allowed.");
	importing = true;
	Vector<String> reloads;
	EditorProgress pr("reimport", TTR("(Re)Importing Assets"), p_files.size());
	Vector<ImportFile> reimport_files;
	HashSet<String> groups_to_reimport;
	for (int i = 0; i < p_files.size(); i++) {
		String file = p_files[i];
		ResourceUID::ID uid = ResourceUID::get_singleton()->text_to_id(file);
		if (uid != ResourceUID::INVALID_ID && ResourceUID::get_singleton()->has_id(uid)) {
			file = ResourceUID::get_singleton()->get_id_path(uid);
		}
		String group_file = ResourceFormatImporter::get_singleton()->get_import_group_file(file);
		if (group_file_cache.has(file)) {
			
			groups_to_reimport.insert(file);
			
			group_file = String();
		} else if (groups_to_reimport.has(file)) {
			
			group_file = String();
		} else if (!group_file.is_empty()) {
			
			groups_to_reimport.insert(group_file);