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/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

How to draw Dynamic Line or Timeseries Chart in Java using jfreechart library?

Today we are going to write a code to draw a dynamic timeseries-cum-line chart in java.   The only difference between simple and dynamic chart is that a dynamic event is used to create a new series and update the graph. In out example we are using timer which automatically calls a funtion after every 1/4 th second and graph is updated with random data. Let's try with the code : Note : I had tried my best to provide complete documentation along with code. If at any time anyone have any doubt or question please post in comments section. DynamicLineAndTimeSeriesChart.java import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.Timer; import javax.swing.JPanel; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.XYPlot; import

Odoo: Download Binary File in v10

To download any binary file in Odoo10 following is the link: http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id> module_name    - the name of the model with the Binary field field_name         - the name of the Binary field object_id            - id of the record containing particular file. field_filename    - name of a Char field containing file's name (optional). So if you want to call a function on button click and download the file, code is as follow: file_url = "http://127.0.0.1:8069/web/content?model=<module_name>&field=<field_name>&filename_field=<field_filename>&id=<object_id>" return {     'type': 'ir.actions.act_url',     'url': file_url,     'target': 'new' } In Reports or web page, you can use it as: <t t-foreach="files&qu