Why are my source code files are not present in the commit despite there being no entry for the file in the .gitignore?
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
When making a commit in my repository, it is possible that you don't see a file that you modified included in the commit. You didn't include this file or the file extension in the .gitignore file.
Cause
We can find out exactly which files gitignore is ignoring and why it is ignoring them with certain git commands.
1
git status --ignored
The above command will show a list of files that are being ignored by git. After you run this command, your file should be listed in the output. If the file is not listed, the reason for the file not being added is not git related and this KB does not apply to you.
If the file is present in the output, we can further check where git is getting instructions from to ignore the file using the below command -
1
git check-ignore -v <filename>
Typically, if gitignore does not contain or match your filename but it is still getting ignored, this is happening because of global gitignore settings. You can configure a global gitignore file with the name -
.gitignore_global
as shown in git documentation. Below is an example -As we can see, two files are being ignored - manage.py and test3.txt. If I want to check which ignore file is being used for test3.txt, I run the next command which gives me the path to the ignore file. Here, it is pointing to a global gitignore.
Solution
Once you find out which file is providing the configuration to git to ignore your files, you can remove it from the gitignore file. If it is a global gitignore, remove the relevant entries from .gitignore_global
to make git recognize and add your files to the repository again.
Was this helpful?