Skip to main content

Github : ignore files


Recently I have started working with git version control system and I’m loving it, especially the Git bash. 

Usually in each and every project there are some files which we don’t want to commit and push on live again and again. For example configuration files and db files once committed don’t need to be modify again for live site. In such cases to stop manual intervention git provide us the facility to ignore files.

Let’s discuss:  

We can ignore files in two ways.

1) Using .gitignore file : 

If you don’t want some files to be added and want to ignore them while uploading on 
server, then you can use .gitignore file. For example you have a file named
bkp_config.php and while pushing you code live you don’t want to push that file.
In such cases you can use .gitignore file.  

There are again two scenarios.

a)     Files have already been tracked.

Means first you have added the files, committed them and then pushed them on master repository. 

Like :

$ git add .

$ git commit -m 'Pushed Code live' 

$ git push origin master
After some time you realized that you shouldn’t have done that. Then you added .gitignore file so that in future git can ignore this file to be committed. 

.gitignore file

//content of .gitignore file 
bkp_config.php

It will use its rules when looking at files to commit. Note that git will not ignore a file that was already tracked before a rule was added to this file to ignore it. In such a case the file must be un-tracked, usually with 

git rm --cached < filename >

So in this case we have to un-track the file first.

Run 

$ git rm --cached 'bkp_config.php'

$ git add .


$ git commit –m ‘message’

$ git push origin master

(when you will commit changes and will push on server and other users have pulled the data then the file will get deleted from their clones request as well.)

Now your files are in un-tracked stage. Now go to point (b).

This file(.gitignore) can be committed into the repository, thus sharing the rule list with any other users that clone the repository.

Note that you can create a .gitignore in any subpath to have its rules applied at that path. Sometimes an empty .gitignore file is used as a placeholder for an empty path, for example to force git to generate a log/ path for your development environment to use.


b)     Files are un-tracked. 

In this case just add the rule in .gitignore file and commit the file. Push it.

If you want to even stop adding .gitignore file then use 

$ echo .gitignore >> .gitignore.

So .gitignore  file will also become un-tracked.

Next time when you will run git add . command ignored files will not get added.

2) Ignore Versioned Files :

There are some files like db.config or config.php which includes different data for local and live server. So such files are once added to the live server and after that we rarely need those to be changed and they would have different data on both local and live files. In that case we can use following command so that whenever we make any changes in local config files we should’t commit it knowingly or mistakenly.  Use

$ git update-index --assume-unchanged <file> 

If you will make any changes in a file then it would not appear in git status list. So will not get added and committed. 

List all files marked as --assume-unchanged

$ git ls-files -v | grep ^[a-z]

If you want to start tracking changes again run the following command:

$ git update-index --no-assume-unchanged <file>  


That's it. Please send me your valuable feedback through comments. All type of suggestions are welcome.

Thanks!!!!!!!!! Enjoy Programming :)

 

Comments

Popular posts from this blog

Odoo: Qweb Templates Cache Issue

Hi Everyone, Today I was working on a hotel booking template in Odoo and changes made in the Qweb template(.xml) were not reflecting on updating module with odoo service restart. Tried few times without any success :(. Finally, I decided to delete the old template from Odoo backend and then update module again and it worked like a charm!! :) Steps to delete template from backend: Settings --> User Interface --> Views --> Search by template name Delete the used template. Although it's a small post, but I'm sure it will meet the purpose and help someone in the future. Thanks!!! Enjoy Programming!! :) Reference Links: =================================== https://www.odoo.com/forum/help-1/question/odoo-cache-and-updating-qweb-templates-84492

Odoo12/13: Add an extra action in the tree view action button

This post will help you to add an action window in Odoo. Odoo13: <act_window id="action_make_bank_payment"              name="Do Bank Payment"              res_model="account.ob.payment"              binding_model="account.move"              view_mode="form"              target="new"              binding_views="list,form"              domain="[('type','=', 'in_invoice')]"              groups="account.group_account_user" /> Odoo12: <act_window id="action_make_bank_payment"              name="Do Bank Payment"              res_model="account.ob.payment"             view_mode="tree,form"              domain="[('type','=', 'in_invoice')]"              groups="account.group_account_user" /> Thanks!!! Enjoy Programming!! :) Reference: https://www.odoo.com/es_

Odoo/OpenERP: one2one relational field example

one2one relational field is deprecated in OpenERP version>5 but you can achieve the same using many2one relational field. You can achieve it in following two ways : 1) using many2one field in both the objects ( http://tutorialopenerp.wordpress.com/2014/04/23/one2one/ ) 2)  using inheritance by deligation You can easily find the first solution with little search over internet so let's start with 2nd solution. Scenario :  I want to create a one2one relation between two objects of openerp hr.employee and hr.employee.medical.details What I should do  i. Add _inherits section in hr_employee class ii. Add field medical_detail_id in hr_employee class class hr_employee(osv.osv):     _name = 'hr.employee'     _inherits = {' hr.employee.medical.details ': "medical_detail_id"}     _inherit = 'hr.employee'         _columns = {              'emp_code':fields.char('Employee Code', si