Removing a file from git repository

One thing I have seen in all the projects that I have worked on is that all of them require a couple of configuration changes before they can be run in the local development environment.

This could range from server configuration files to specific user login hacks. And if you are lucky, the list of changes would be too long. This means, if you are working with git, your change file list would always have this long list of configuration changes.

So, there are a couple of things you can do here. One of them is add them to .gitignore file. When you tell Git to ignore files, it’s going to only stop watching changes for that file, and nothing else. This means that the history will still remember the file and have it.

I would rather go with removing the file from repository altogether. You could use the command,

$ git rm --cached <file>

This would remove the file from repository, but will keep it in the workspace or file system.

This can be reverted by manually adding the file back using add.

Or, if you want to tell the repository to stop tracking a file, you could use

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

And this can be reverted using

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

Read more about this here and here..

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s