14

I have a log file errors.log which the software uses to report errors. The software does not create errors.log by itself, so the file must exist before hand.

The problem is, if I add it to .gitignore then developers would need to create it manually on their machines. If I don't ignore it, then each developer would be committing their own errors.log contents after testing... proving a large hassle when merging.

How do I make it so that new developers acquire a blank copy of errors.log when they initially clone it, but it is not added to working tree (regardless of changes) when git add -A is used?

1615903
  • 32,635
  • 12
  • 70
  • 99
Dellowar
  • 3,160
  • 1
  • 18
  • 37
  • As far as I'm aware, you can't. Devs only need to create the file once per clone, that doesn't seem like a major hardship, but you could add a script to do it for them. – jonrsharpe May 23 '17 at 20:52
  • 1
    Note that setting one of the index flag bits (`--assume-unchanged` or `--skip-worktree`) must be done in *every* clone. That's *precisely as much work as creating the empty `errors.log` file*. You might as well just create the `errors.log` file. – torek May 23 '17 at 22:50
  • Does this answer your question? [Git - Difference Between 'assume-unchanged' and 'skip-worktree'](https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree) – TheBrenny Jun 04 '20 at 00:58

2 Answers2

12

Update

The best way for this case is skip-worktree

skip-worktree, according this answer even where git knows that the file has been modified (or needs to be modified by a reset --hard or the like), it will pretend it has not been, using the version from the index instead. This persists until the index is discarded.

Another option, assume-unchanged is designed for cases where it is expensive to check whether a group of files have been modified

git update-index --assume-unchanged FILE_NAME

and if you want to track the changes again use this command:

git update-index --no-assume-unchanged FILE_NAME
developer_hatch
  • 15,898
  • 3
  • 42
  • 75
  • 1
    Would each dev need to run this after their original clone? Is there no 'automatic' way for the repo to assume this after cloned? – Dellowar May 23 '17 at 20:57
  • I updated the answer acording the new information, so yes, there is a better way, and it is using skip-worktree :) – developer_hatch May 24 '17 at 12:33
4

You want to use the skip-worktree feature (and not assume-unchanged) like described in https://stackoverflow.com/a/13631525/717372

Philippe
  • 28,207
  • 6
  • 54
  • 78