Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Git, how to commit file once, but ignore further changes to the file

Tags:

git

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?

like image 762
Dellowar Avatar asked May 23 '17 20:05

Dellowar


2 Answers

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
like image 95
A Monad is a Monoid Avatar answered Nov 07 '22 09:11

A Monad is a Monoid


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

like image 35
Philippe Avatar answered Nov 07 '22 10:11

Philippe