11

We're migrating from Perforce to GIT. In perforce, there were some files that I'd want in the repository, but they shouldn't be checked in by individual developers regularly. Things like eclipse project files. Each dev might get the initial .project file, but then tweak it slightly for their environment.

With P4, I could take those files, put them in a separate changelist and forget about them. Syncing wouldn't overwrite them and they wouldn't get committed when I commited my default changelist.

Is there a way to do something similar with GIT?

I'd like to still be able to "git commit -a"

Marc Hughes
  • 5,808
  • 3
  • 36
  • 46
  • possible duplicate of [Committing Machine Specific Configuration Files](http://stackoverflow.com/questions/1396617/committing-machine-specific-configuration-files) – Senseful Sep 03 '14 at 19:36
  • Possible duplicate of [Can I 'git commit' a file and ignore its content changes?](https://stackoverflow.com/questions/3319479/can-i-git-commit-a-file-and-ignore-its-content-changes) – Trevor Boyd Smith Dec 13 '17 at 19:40
  • *I'd like to still be able to "git commit -a"* -- that's precisely your problem, right there. With `git`, you generally do not just commit everything, you review what has changed with `git status` and `git diff`, you decide what to add (or to `.gitignore`), and then commit precisely what you need. This workflow ensures that your commits do not contain any cruft like accidentally checked in object or temporary files, etc. See, creating a `git` history is telling a story, and the better you tell it, the more useful it will be. Better not smudge it with mindless commit-my-pile-of-garbage. – cmaster - reinstate monica Jan 29 '18 at 16:14

2 Answers2

11

You are probably looking for

git update-index --assume-unchanged .project

Aristotle Pagaltzis
  • 112,955
  • 23
  • 98
  • 97
6

If you need a common base for those (.project, .classpath, ...), you can:

  • version template version of those files (.project_tpl, .classpath_tpl, ...)
  • use a filter driver to generate, on checkout, the actual files (which won't be versioned, and only modified locally by the developers)

alt text

(the 'clean' step during commit wouldn't do anything for those templates.
Only the 'smudge' step is used here, to generate the private files)

Note: this is a slight "mis-use" of a filter driver, which is supposed to process only file contents, not to generate new ones.
But it could help you in your scenario (provided your 'smudge' script doesn't overwrite blindly the eclipse files if they happen to already be here.)

ax.
  • 58,560
  • 8
  • 81
  • 72
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    So I could create a fairly dumb smudge routine that removes .tmpl from anything with a .tmpl extension. I could then add .project.tmpl or configuration.xml.tmpl to git and when people pull them they get .project or configuration.xml I guess I could also add those generated files to .gitignore and be golden. – Marc Hughes Jul 23 '10 at 14:04