Jun 9, 2015

Git: Ignore deleted files

Sometimes working with other people you with you didn't have some of the files in repository because they are getting in the way of your settings. .ruby-version for instance.

You check out the repository and what the...

$ git clone ...
...
rbenv: version '2.1.5' is not installed

Okay you delete the pesky .ruby-version but now it is there for every commit:

$ rm .ruby-version
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    .ruby-version

It's impossible to ignore it by adding to .gitignore but fortunately in git there is an option for everything.

$ git update-index --assume-unchanged .ruby-version
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

Done! Phew, at least this wasn't too much typing, was it? Another option is to truncate the file:

$ cat >> ~/.gitignore
.ruby-version
^C
rbenv: version '2.1.5' is not installed
$ cat > .ruby-version
^C
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

And as always be careful with git, don't mess things up.

Hello!

Nick Ostrovsky

Full-stack designer. I like to keep things as minimal and as simple as possible.

Started to program with Sinclair Spectrum and has moved to user experience and interfaces since. Developed and contributed to projects for major brands such as L'Oreal, JTI and AB InBev among others. I am currently working as an independent contractor.

I live in Phuket, Thailand and enjoy the beautiful scenery with wife and two daughters.