Git uses gitignore to create project filtering rules (transfer)

In the process of collaborative development code management, some temporary files, configuration files, or generated files are often encountered. These files will be different due to different development ends. If you use git add . All files are included in the git library , then there will be frequent changes and pushes, which will cause development inconvenience.

Git can easily help us solve this problem, that is, to establish project file filtering rules.

There are two filtering mechanisms in git, one is a global filtering mechanism, which is applicable to all gits; the other is a filtering rule used for a certain project. Personally prefer the second.

 

Take one of my projects as an example. The project is developed with .net. The .config file, including the generated bin/Debug, bin/Release files, etc., I hope not to join git management.

Create a .gitignore file in the code directory: vim .gitignore , the contents are as follows:

 

[plain] view plain copy
  1. #Filter database files, sln solution files, configuration files  
  2. *.mdb  
  3. * .ldb  
  4. *.sln  
  5. *.config  
  6.   
  7.   
  8. #Filter folders Debug, Release, obj  
  9. Debug/  
  10. Release/  
  11. obj/  

 

Then call git add. and execute git commit.

Problem: .gitignore only works for files that haven't been added to the git repository. If it has been added, you need to use git rm to remove it and then re-commit.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326615828&siteId=291194637