1

I'm trying to ignore all changes to a very small file in my repo (Github). It is a hidden file (.first_run), which contains a single character (0). I use it (obviously) to detect a first run of my package.

I'm encountering these issues:

  1. The file is already tracked, so adding it to my .gitignore won't work.
  2. I can't use git rm --cached <file> because it will remove that file from the repo, which is not what I want.
  3. Using git update-index --assume-unchanged <file> also does not work. If, after applying assume-unchanged to the file, I change the 0 for a longer string (e.g.: sdfgdgd), it does not show as changed (correct behaviour) But if I change the 0 for say a 4, it will show up as modified.

I assume the issue described in point 3. is due to what is explained in this answer:

Assume-unchanged (..) is not a promise by Git that Git will always consider these paths are unmodified---if Git can determine a path that is marked as assume-unchanged has changed without incurring extra lstat(2) cost, it reserves the right to report that the path has been modified (as a result, "git commit -a" is free to commit that change).

Is there anything I can do to make git ignore future changes to this file?

Community
  • 1
  • 1
Gabriel
  • 40,504
  • 73
  • 230
  • 404

2 Answers2

5

You should be able to stop tracking changes on the file with:

git update-index --skip-worktree <file>

And you can resume tracking changes with:

git update-index --no-skip-worktree <file>
Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
1

I believe there is no way to do exactly what you want.

But how about changing the application logic? I.e., instead of checking the content, check for existance. If the file does not exist, your app has not been run before. Remove it from the repository and add it to .gitignore. On first run, let your application create the file with whatever content you need.

AnoE
  • 8,048
  • 1
  • 21
  • 36
  • 1
    Thanks AnoE, but that logic won't work in my case. The `.first_run` file contains any integer from `0` to `4`, and they all mean a different thing. +1 for giving an alternative. – Gabriel Jul 25 '16 at 15:01
  • If I understand you correctly, the `0` is the initial value (stored in the repository); and your application writes the other values, probably after doing some initialization steps. If I understood that correctly, then I still don't see why you cannot deliver the app with "file does not exist", your app can still create it and save its several numbers, right? Since it will be in `.gitignore`, you will never see it again... – AnoE Jul 25 '16 at 15:09
  • I think you are correct, I could do that but I'd had to change my code. Jeff's answer does not require me to change anything, so I selected that one. Thank you! – Gabriel Jul 25 '16 at 17:50