threads / discuss / 61867

Tracked file cannot be added, mentions to sparse checkout that I don't have.

Subject: Tracked file cannot be added, mentions to sparse checkout that I don't have.

## tl;dr

2 messages between Jul 30, 2024 and Jul 30, 2024.

replies: 1people: 2as markdown or json

Nathan Teodosio· Jul 30, 2024, 10:29 UTC · lore
What did you do before the bug happened? (Steps to reproduce your issue)
I modified a tracked file.
What did you expect to happen? (Expected behavior)

The file is listed as modified in git status and added with git add etc., i.e. the usual commit routine.

What happened instead? (Actual behavior)
I cannot add or commit the changes done to that file.

---> % echo 1 >> snapcraft.yaml % tail -n1 snapcraft.yaml 1 # I expected snapcraft.yaml to show here: % git status -s ?? git-bugreport-2024-07-30-1212.txt # I expected snapcraft.yaml to be added here: % git add snapcraft.yaml The following paths and/or pathspecs matched paths that exist outside of your sparse-checkout definition, so will not be updated in the index: snapcraft.yaml hint: If you intend to update such entries, try one of the following: hint: * Use the --sparse option. hint: * Disable or modify the sparsity rules. hint: Disable this message with "git config advice.updateSparsePath false" <---

What's different between what you expected and what actually happened?

The difference is that the file cannot be added or commited, as if no changes had been made to it.

Anything else you want to add:

---> % git branch --show-current dev % git ls-tree -r dev --name-only|grep snapcraft snapcraft.yaml % git sparse-checkout list fatal: this worktree is not sparse <---

Git was yesterday in my system updated and I never encountered anything similar to this issue before.

---> % grep ' installed git:' /var/log/dpkg.log 2024-07-29 10:37:19 status installed git:amd64 1:2.45.2-1ubuntu1 <---

Git does recognize modifications to another file in the same directory, so I am completely stumped what is special about this snapcraft.yaml.

[System Info] git version: git version 2.45.2 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64 compiler info: gnuc: 13.2 libc info: glibc: 2.39 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]
brian m. carlson· Jul 30, 2024, 22:40 UTC · re: Nathan Teodosio · lore

Re: Tracked file cannot be added, mentions to sparse checkout that I don't have.

On 2024-07-30 at 10:29:26, Nathan Teodosio wrote:
Show 31 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> I modified a tracked file.
> 
> What did you expect to happen? (Expected behavior)
> 
> The file is listed as modified in git status and added with git add etc.,
> i.e. the usual commit routine.
> 
> What happened instead? (Actual behavior)
> 
> I cannot add or commit the changes done to that file.
> 
> --->
> % echo 1 >> snapcraft.yaml
> % tail -n1 snapcraft.yaml
> 1
> # I expected snapcraft.yaml to show here:
> % git status -s
> ?? git-bugreport-2024-07-30-1212.txt
> # I expected snapcraft.yaml to be added here:
> % git add snapcraft.yaml
> The following paths and/or pathspecs matched paths that exist
> outside of your sparse-checkout definition, so will not be
> updated in the index:
> snapcraft.yaml
> hint: If you intend to update such entries, try one of the following:
> hint: * Use the --sparse option.
> hint: * Disable or modify the sparsity rules.
> hint: Disable this message with "git config advice.updateSparsePath false"
> <---

Have you perhaps done `git update-index --skip-worktree snapcraft.yaml`? Here's how you can find out:

  % git ls-files -t | grep snapcraft.yaml
  S snapcraft.yaml

That "S" means it's skip-worktree. Otherwise, we'd normally expect to see an "H" or maybe another letter there.

If so, that might be because you've received some information (unfortunately erroneous) that `git update-index --skip-worktree` or `git update-index --assume-unchanged` are good ways to ignore changes to a tracked file. The Git FAQ[0] is pretty clear that Git doesn't allow ignoring tracked files and explains why. The skip-worktree bit is designed to implement sparse checkout, so that's why you typically get that message if that bit is set and you try to add the file.

You can unset that bit with `git update-index --no-skip-worktree snapcraft.yaml`, which should fix the problem. As for ignoring files, the Git FAQ outlines an alternative which we recommend instead:

  If your goal is to modify a configuration file, it can often be
  helpful to have a file checked into the repository which is a template
  or set of defaults which can then be copied alongside and modified as
  appropriate. This second, modified file is usually ignored to prevent
  accidentally committing it.

Hopefully that's helpful. If I'm incorrect and that bit hasn't been set in the index, please do let us know, because that would be unexpected.

[0] https://git-scm.com/docs/gitfaq#ignore-tracked-files
-- 
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA

← back to recent threads