My scrapbook about almost anything I stumble upon in my tech world. If you find anything useful don't forget to give thumbs-up :)

Breaking

Friday, August 16, 2024

Which GITIGNORE is ignoring the file?


If you are receiving the error message like below when you are trying to add a file into git repository - 
> git add a.log
The following paths are ignored by one of your .gitignore files:
a.log
hint: Use -f if you really want to add them.
hint: Disable this message with "git config advice.addIgnoredFile false"
This means, .gitignore file is active in your shell environment and working as expected. The problem arise when you have enabled multiple .gitignore files active and you have to alter the file which is actually ignoring this particular file (a.log in our case). 

Git provides a very straight forward command to check which file and rules are actually ignoring the file, which is git check-ignore -v FILE 

Let's see, how to use that command and make sense of output printed - 
> git check-ignore -v a.log
/Users/Atul/.oma_gitignore_global:25:*.log a.log
Here, the First part (/Users/Atul/.oma_gitignore_global) is the file name which is ignoring the file.
Second part (25) is the line no in gitignore file which has the ignore rule (*.log), which you can check as below - 
> head -25 /Users/Atul/.oma_gitignore_global | tail h
*.log
and the Last part (a.log) is the name of file which is being ignored. If that's a mistake, you now know which is ignoring the file, edit that as per your requirement. 

Happy Learning !!


Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group


No comments:

Post a Comment

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.