1

I have two files: statsabove.ejs and statsbelow.ejs which I want to be included in my git repository but I don't want to them to be updated (so that they stay empty when I upload them to GitHub even if my local versions have data inside).

How do I do that?

I did git rm --cached and also added them to .gitignore but what happened is that they disappeared from the repo completely. This is not what I want.

I want them to always stay inside the repository and to always stay the same (empty, that is), even if my local versions have data in them.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Aerodynamika
  • 7,883
  • 16
  • 78
  • 137
  • 1
    Possible duplicate of [Git - Difference Between 'assume-unchanged' and 'skip-worktree'](https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree) – MrTux Mar 10 '18 at 00:26
  • 3
    Note that this generally is the wrong solution - the right one is to *not* add the files to Git, ever, *do* keep them in `.gitignore`, and simply *create* them on the client automatically. If you have already added them to Git, though, you have a problem: you cannot remove them safely. – torek Mar 10 '18 at 00:44
  • 1
    `assume-unchanged` and `skip-worktree` have a side effect. A merge to the current branch, including `git merge`, `git rebase`, `git cherry-pick`, `git pull`, and etc., would fail if the assume-unchanged or skipped file is actually changed. Git suggests you to commit or stash the changes but both will fail too, because they are assum-unchanged or skipped. Better not to track them in the first place, as @torek suggests. – ElpieKay Mar 10 '18 at 04:19

1 Answers1

2

First, git add and git commit your empty file, say statsabove.ejs.

Then you can run the following command:

git update-index --skip-worktree statsabove.ejs

It tells Git to ignore the changes you make to this file.

This is local though. It means you'll have to run this git update-index command for each clone of your repository.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56