Monday 30 January 2017

How to Fixed .gitignore file if not working


If you are an user of the GIT version control then you must be aware of the .gitignore file. For the ones how are not aware of this file, .gitignore helps you ignore or avoid certain files from being committed into the main repository using GIT.
Now it happens at times that the .gitignore file behaves weirdly and GIT fails to ignore all the file names listed in the .gitignore file and as a result all these files which you do not want to be committed into the repository start getting committed. And when your .gitignore file is not working, its a big mess!
A very very quick fix to this problem would be to get rid of any trailing whitespace in the .gitignore file, if you find one. Also, you should not put any comments next to the listed file in the .gitignore
If all this still does not solve your problem, follow these steps:
Step 1: Commit all your pending changes in the repo which you want to fix.
Step 2: Now you need to remove everything from the git index in order to refresh your git repository. This is safe. Use this command:
git rm -rf --cached .
Step 3: Now you need to add everything back into the repo, which can be done using this command:
git add .
Step 4: Finally you need to commit these changes, using this command:
git commit -m ".gitignore Fixed"
Please let us know if you were able to fix .gitignore using these steps.


Ignore changes to committed files

Temporarily ignore changes

During development it's convenient to stop tracking file changes to a file committed into your git repo. This is very convenient when customizing settings or configuration files that are part of your project source for your own work environment.
> git update-index --assume-unchanged <file>
Resume tracking files with:
> git update-index --no-assume-unchanged <file>

Permanently ignore changes to a file

If a file is already tracked by Git, adding that file to your .gitignore is not enough to ignore changes to the file. You also need to remove the information about the file from Git's index:
These steps will not delete the file from your system. They just tell Git to ignore future updates to the file.
  1. Add the file in your .gitignore.
  2. Run the following:
    > git rm --cached <file>
    
  3. Commit the removal of the file and the updated .gitignore to your repo.

Anonymous

Author & Editor

A technology enthusiast and addictive blogger who likes to hacking tricks and wish to be the best White Hacket Hacker of the World.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.