From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Nathan Teodosio <nathan.teodosio@canonical.com>
Cc: git@vger.kernel.org
Subject: Re: Tracked file cannot be added, mentions to sparse checkout that I don't have.
Date: Tue, 30 Jul 2024 22:40:04 +0000 [thread overview]
Message-ID: <ZqlrxFrzuC2lGyTU@tapette.crustytoothpaste.net> (raw)
In-Reply-To: <20240730122926.638a9263@canonical>
[-- Attachment #1: Type: text/plain, Size: 2685 bytes --]
On 2024-07-30 at 10:29:26, Nathan Teodosio wrote:
> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
prev parent reply other threads:[~2024-07-30 22:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-30 10:29 Tracked file cannot be added, mentions to sparse checkout that I don't have Nathan Teodosio
2024-07-30 22:40 ` brian m. carlson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZqlrxFrzuC2lGyTU@tapette.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@vger.kernel.org \
--cc=nathan.teodosio@canonical.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).