Latest Updates

Post Top Ad

21 August, 2021

Ignore specific files while committing in Git

   

Steps to Ignore specific files while committing into Git


To ignore some specific files, or to ignore some specific extension of file while committing we can achieve this in git.To do so we have to follow the steps:





  • Create one hidden file .gitignore
  • Update file formats that you want to ignore
  • Add .gitignore file to stagging area
  • commit .gitignore file
  • Create dummy files with specific extensions that you want to ignore
  • Add, commit and check the status 

1. Create one hidden file .gitignore

use vi editior to create .gitignore file.

[root@ip-172-31-4-81 piyush]# vi .gitignore

2. Update file formats that you want to ignore



3. Add .gitignore file to stagging area
git add .gitignore

initially .gitignore shows as an untracked file. Once we add to the stagging area it will show as Changes to be committed.



4. Commit .gitignore file

git commit -m "Ignore specific file format"



5. Create dummy files with specific extensions that you want to ignore
Following files extension added to .gitognore
*.css
*.java
*.exe

we have create various files with .css .java .exe and .txt extensions. As per theory if we add to stagging area git will not ignore these extentions


6. Add, Commit and Check the Status

git add . 
Showing only .txt extention files and ignored .css, .java and .exe


git commit -m "Ignore .css .java and .exe files"

After committing the only devops.txt and lab.txt commited.


git log

git log shows the latest commit id with the message.


git show 4b04febe71f25e

This command shows all metadata of commit.


Let us touch one more file piyush.java extension and check the status.

We can see git status is not showing piyush.java because .java extension is added in .gitignore file.



 
But, when I add prakash.txt file, git status adds it to the working directory as an Untracked file.







Please Subscribe and Like

No comments:

Post Top Ad

Your Ad Spot

Pages