0

I make changes in db/schema.rb, but Git doesn't see them while the file isn't included in .gitignore.

It's worth to mention that the editor (Sublime Text) doesn't grey out the file as it does for the files and folders listed in .gitignore.

I checked the following but none of them helped:

$ vi ~/.gitignore
$ git status -s --ignored
$ git check-ignore -v db/schema.rb
Artem Kulakov
  • 29
  • 1
  • 5
  • You could check your global gitignore. It might be named anything like `.gitignore_global`, so I would check its name inside `~/.gitconfig` just to be sure. – LSE Jun 21 '21 at 09:25
  • What do `git ls-tree -r HEAD db/schema.rb` and `git ls-files -v db/schema.rb` print? – ElpieKay Jun 21 '21 at 09:32
  • 1
    There is a hidden flag `assume-unchanged`, which can be set/unset using [`git update-index`](https://git-scm.com/docs/git-update-index#Documentation/git-update-index.txt---no-assume-unchanged). One way to know if your file has this flag is to run `git ls-files -v db/schema.rb` and see if the initial status letter is lowercase (e.g : `h` instead of `H`) -- see [this question](https://stackoverflow.com/questions/2363197/can-i-get-a-list-of-files-marked-assume-unchanged) for example. – LeGEC Jun 21 '21 at 09:38
  • or [this question](https://stackoverflow.com/questions/66971181/git-ignores-local-changes-to-file/66977314) – LeGEC Jun 21 '21 at 09:44
  • @LSE `~/.gitconfig` mention only `.gitignore_global` which is empty – Artem Kulakov Jun 21 '21 at 09:56
  • @ElpieKay The first command gives "100644 blob 0f66d485ba77badc359b5e7fe81c483f19d08c8a db/schema.rb" – Artem Kulakov Jun 21 '21 at 09:57
  • @ElpieKay The second command gives "S db/schema.rb" – Artem Kulakov Jun 21 '21 at 09:58
  • @ArtemKulakov `S` indicates the files has the flag `skip-worktree`. You could try `git update-index --no-skip-worktree db/schema.rb` to cancel the flag. – ElpieKay Jun 21 '21 at 10:47
  • Note that the skip-worktree flag can only be *set* by running `git update-index`; you must have done this, or used a command that did this for you, earlier. – torek Jun 21 '21 at 19:14

1 Answers1

1

From your comment :

The second command gives S db/schema.rb

The S indicates the skip-worktree flag, one of the not so visible flags that can be set through git update-index.

Run :

git update-index --no-skip-worktree db/schema.rb

to remove this flag.


references to the documentation :

The link with git ls-files to spot files having this flag is only mentioned in

  • this small sentence on git help update-index (last sentence in second paragraph in the "Using “Assume Unchanged” Bit", no direct mention from Skip-worktree paragraphs) :

To see which files have the "assume unchanged" bit set, use git ls-files -v (see git-ls-files[1]).

-t

[...] This option identifies the file status with the following tags (followed by a space) at the start of each line:

[...]

S
skip-worktree

-v

Similar to -t, but use lowercase letters for files that are marked as assume unchanged (see git-update-index[1]).

LeGEC
  • 46,477
  • 5
  • 57
  • 104