13

I have a tracked database (already added) file in git. I want this file to always contain the same data in my git repository. Even when I modify it in the working copy (local sandbox) for test purposes.

With git, how to exclude this changed file on my working copy from a commit ?

djondal
  • 2,521
  • 3
  • 24
  • 40
  • 1
    Possible duplicate: http://stackoverflow.com/questions/3319479/git-can-i-commit-a-file-and-ignore-the-content-changes – Daenyth Jul 28 '10 at 15:42

6 Answers6

21

The way to ignore certain files that are already committed is

git update-index --assume-unchanged file

However, this is a local setting, and it doesn't propagate when cloning.

Its effect is canceled with git update-index --no-assume-unchanged gui.

P Shved
  • 96,026
  • 17
  • 121
  • 165
4

Additionally to using git add I would suggest to use a shell with more capabilities, i.e. zsh. Here you can insert extended globbing like *~*.o(.) which means all files except such ending with o. This make it easier to add all files except one. Zsh also allows you to set a global alias: alias -g AF="*~*.o(.)". So you can type git add AF and it will be expanded in the right way.

qbi
  • 2,104
  • 1
  • 23
  • 35
2

If you don't do git commit -a, git commit will only commit files that you have explicitly added to the index using git add.

jdizzle
  • 4,078
  • 1
  • 30
  • 38
-1

simply do not add it with git add, but add any other file you want to commit

then use git commit instead of git commit -a

opatut
  • 6,708
  • 5
  • 32
  • 37
-2

The smarter way to do this is to not track the database at all, directly. Track an example database and then each developer can copy it and modify it, and it can be under gitignore.

Daenyth
  • 35,856
  • 13
  • 85
  • 124
  • -1. Not helpful. Anyway, sometimes you can't do this because external framework **modifies** file during build, and can't generate it at the same time. – P Shved Jul 28 '10 at 15:44
  • 2
    If my file is tracked, it is because it should be tracked... It is just that I do not want to propagate the changes I make on a testing level. – djondal Jul 28 '10 at 15:45
-3
  1. add this file to your repo
  2. commit
  3. add it to .gitignore file
  4. commit .gitignore file
zed_0xff
  • 32,417
  • 7
  • 53
  • 72