Re: Ignore specific changes but not the entire file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2024-03-28 at 07:46:08, Mohammad Al Zouabi wrote:
> The problem with:
> 
> ```sh
> git update-index [--skip-worktree|--assume-unchanged]
> ```
> 
> Is that it ignores the entire file.
> 
> Is there a plan to support something that remembers what was exactly
> ignored, and if there are changes to it, either un-ignore the file, or
> display the hunks that were changed?

No, because the Git FAQ is clear that Git doesn't support ignoring
tracked files at all[0]:

    Git doesn’t provide a way to do this. The reason is that if Git
    needs to overwrite this file, such as during a checkout, it doesn’t
    know whether the changes to the file are precious and should be
    kept, or whether they are irrelevant and can safely be destroyed.
    Therefore, it has to take the safe route and always preserve them.

    It’s tempting to try to use certain features of git update-index,
    namely the assume-unchanged and skip-worktree bits, but these don’t
    work properly for this purpose and shouldn’t be used this way.

    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.

So the functionality that you're using is not intended to be used that
way and in fact is broken for that purpose in a variety of subtle ways
that you'll notice if you keep using it.

If you need to generate files from a variety of sources, some of which
should be tracked and some which should not, you can do something like
create a directory foo.cfg.d, and use a script to include files from
that directory to generate your config (which would be in an ignored
file).  You can have some of those files be tracked (and hence
diffable), and others be ignored, and then the script can generate the
proper data.  This same approach is used on Unix systems for generating
configuration files and is well known, so it shouldn't be too difficult
to configure in most cases.

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

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux