Git Ignore:
- If we want to ignore some files from our git repository from being tracked and not to delete those then we will use git ignore.
- We need to create a file with name ".gitignore" in project root folder and write the files to exclude in that using wild cards like *,. etc see references for more info.
Important usecase use case:
Let us imagine a scenario where you want to ignore all .class files of a git project.So you created .gitignore file and inserted below line *.class.You moved .gitignore file to staging area and then commited.Every thing is working fine but there are few .class files which are already commited.So to exclude all the commited .class files we will follow below steps.
Step1:Lets commit all files and make working tree as clean
Step2:Use this cmd "git rm -r --cached ." ,this will move all files(ot only .class files but all commited files in your project ) to working directory.
Step3:Re add every thing using "git add .",all files will be moved to staging area.
Step 4:now commit all files.
As the all files are moved to working area all .class files are untracked and are ignored.
To have detailed explanation on this scenario,have a look at this:http://www.codeblocq.com/2016/01/Untrack-files-already-added-to-git-repository-based-on-gitignore/
0 Comments