1

I'm new to Git and I use this command before committing:

git add .

and it adds some files I don't want to be tracked like: temp files

.tmp_basictest-barchart.html.84279~
.tmp_basictest-demo.html.84399~ 

and hidden files:

.project

How to avoid these files to be added ?

hippietrail
  • 15,848
  • 18
  • 99
  • 158
BiAiB
  • 12,932
  • 10
  • 43
  • 63

2 Answers2

5

Make a file called ".gitignore" and add the filenames to it. .gitignore should be in your root directory, but you can use it in any directory (like an ".htaccess" file).

makdad
  • 6,402
  • 3
  • 31
  • 56
  • 1
    this solution would do the trick for the .project file, but it's not usable for temp files which are numerous and which names are varying, unless a pattern can be provided. – BiAiB Apr 10 '11 at 10:34
  • 3
    adding `.tmp_*` should do the trick. If there is a specific tmp file you would like to add to the version control add `!.tmp_something` to "unignore" it. – Jakobinsky Apr 10 '11 at 10:45
  • I've just tested and it worked great, accepted answer ! btw, found the .gitignore spec here: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html – BiAiB Apr 10 '11 at 11:50
  • @Jakobinsky should get more credit here - he gave you the answer you were really seeking :) – makdad Apr 11 '11 at 03:41
0

Git commands generally ignore

  • Patterns read from the command line for those commands that support them.

  • Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file. These patterns match relative to the location of the .gitignore file. A project normally includes such .gitignore files in its repository, containing patterns for files generated as part of the project build.

  • Patterns read from $GIT_DIR/info/exclude.

  • Patterns read from the file specified by the configuration variable core.excludesfile.

sehe
  • 374,641
  • 47
  • 450
  • 633
  • pointing to the actual source(http://www.kernel.org/pub/software/scm/git/docs/gitignore.html) would have helped more than copypasting without mentionning it. – BiAiB Apr 10 '11 at 11:54
  • Right. I was extending on phooze's answer. I had no intention to get any credits here. Just letting folks know there is a little more to it than only that (it seems that if people were so apt at reading man pages, these question would not occur so frequently). I'll ref the source next time – sehe Apr 10 '11 at 13:27