Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git Track File Existance Only, Not File Contents

Tags:

git

gitignore

Is there any way to tell Git to track a file's existence, but not to track the content of the file? I would like Git to create a file if it doesn't already exist when git pull is run, but to otherwise ignore the file.

This would be highly useful for error_logs ect in a web-app I am developing.

like image 212
user2121874 Avatar asked Sep 10 '25 21:09

user2121874


1 Answers

A native way to do this (beside git-annex) is to:

  • track a file template
  • version a script which is able, on checkout, to generate the file from the file template (if the file doesn't exist yet): that file won't be versioned and will remain private.
    The script knows how to generate that file or from where to copy it.
  • declare in a .gitattribute file a content filter driver: a smudge script which will run automatically on checkout and will reference the script mentioned in the previous point.

http://git-scm.com/figures/18333fig0702-tn.png

(image from "Customizing Git Attributes" " from the Git Book)

like image 66
VonC Avatar answered Sep 13 '25 11:09

VonC