Error after removing submodule: The following path is ignored by one of your .gitignore files:
Asked Answered
A

4

12

I'm getting this error after I've removed a submodule. The path in question is not in my .gitignore file, nor is there anything relevant in my .git/info/exclude file. I don't have a .gitignore_global file. Why is git trying to ignore this path and how can I fix this?

The following path is ignored by one of your .gitignore files:
MyTest/MyTest/lib/submodules/ScreenRecorder
Use -f if you really want to add it.

This is the command I'm trying to execute:

git submodule add https://github.com/kishikawakatsumi/ScreenRecorder.git MyTest/MyTest/lib/submodules/ScreenRecorder

This is being executed from my git repos root directory.

Adaminah answered 2/4, 2013 at 13:52 Comment(4)
It would be a good idea to actually post the path which is ignored and where it exactly lies under your directory structure.Kinship
@Kinship just added that infoAdaminah
Thanks. What exact commands are you executing when getting this error?Kinship
@Kinship added that info as wellAdaminah
B
2

Removing the relevant [submodule] stanza in my .git/config solved the issue for me.

My guess that the superrepo will automatically ignore all files in submodules since they are not tracked. Therefore, if there is a stray [submodule] stanza in your config, git will add the path as an ignore pattern.

Berlin answered 13/5, 2013 at 12:27 Comment(0)
F
3

As mentioned in "Git is ignoring files that aren't in gitignore"

Another reason for receiving this error message from Git is when executing the git submodule add command while a previous git command has crashed and left the lock file
(this can happen, for instance, when you use custom scripts which include git commands and you haven't noted the crash).

In that case, an error message like "The following path is ignored by one of your .gitignore files" is not very expressive.

With Git 2.26 (Q1 2020), said error message generation is improved for "git submodule add ".

See commit c816385 (08 Jan 2020) by Kyle Meyer (kyleam).
(Merged by Junio C Hamano -- gitster -- in commit 25794d6, 05 Feb 2020)

submodule add: show 'add --dry-run' stderr when aborting

Signed-off-by: Kyle Meyer

Unless --force is specified, 'submodule add' checks if the destination path is ignored by calling 'git add --dry-run --ignore-missing', and, if that call fails, aborts with a custom "path is ignored" message (a slight variant of what 'git add' shows).

Aborting early rather than letting the downstream 'git add' call fail is done so that the command exits before cloning into the destination path.

However, in rare cases where the dry-run call fails for a reason other than the path being ignored --- for example, due to a preexisting index.lock file --- displaying the "ignored path" error message hides the real source of the failure.

Instead of displaying the tailored "ignored path" message, let's report the standard error from the dry run to give the caller more accurate information about failures that are not due to an ignored path.

For the ignored path case, this leads to the following change in the error message:

The following [-path is-]{+paths are+} ignored by one of your .gitignore files:
<destination path>
Use -f if you really want to add [-it.-]{+them.+}

The new phrasing is a bit awkward, because 'submodule add' is only dealing with one destination path.

Alternatively, we could continue to use the tailored message when the exit code is 1 (the expected status for a failure due to an ignored path) and relay the standard error for all other non-zero exits.

That, however, risks hiding the message of unrelated failures that share an exit code of 1, so it doesn't seem worth doing just to avoid a clunkier, but still clear, error message.

So you will get a more explicit fatal:... error message mentioning the index.lock, instead of an "ignored path"

Freitag answered 6/2, 2020 at 17:4 Comment(0)
B
2

Removing the relevant [submodule] stanza in my .git/config solved the issue for me.

My guess that the superrepo will automatically ignore all files in submodules since they are not tracked. Therefore, if there is a stray [submodule] stanza in your config, git will add the path as an ignore pattern.

Berlin answered 13/5, 2013 at 12:27 Comment(0)
D
2

I've found that Git for Windows will also throw this error if you are trying to add a local folder, and use Windows-style backslashes instead of Linux-style forward-slashes for the path.

For example, the following command will complain that the path is ignored in .gitignore (even if you don't have a .gitignore file):

git submodule add C:\mysubmodule\

The solution is to change to forward-slashes:

git submodule add C:/mysubmodule/
Diatomite answered 1/3, 2020 at 12:7 Comment(0)
S
0

Remove the existing .gitignore file and create a new one worked for me.

Sandblast answered 24/10, 2016 at 15:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.