Re: .gitignore is not enough

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

 



On 2023-08-03 at 17:17:15, Johannes Sixt wrote:
> Am 03.08.23 um 07:35 schrieb Hilco Wijbenga:
> > I think you might be looking for "git update-index --assume-unchanged
> > <file>"? See https://www.git-scm.com/docs/git-update-index for more
> > details.
> 
> Sorry to tell you that this is a myth that lives on because it is
> repeated over and over again.

This is indeed false.

> > This allows you to tell Git to ignore the changes you made to that
> > (tracked) file.
> 
> No. --assume-unchanged allows you to make the *promise* to Git that you
> will not change the file, and consequently Git does not have to check
> whether the file was changed. If you break the promise (because you
> change it), you will get what you deserve. For example, you may find
> that Git overwrites your changes, or commits them nevertheless.
> 
> Perhaps a better choice is --skip-worktree, but recent answers on
> Stackoverflow point out that even that is not a suitable solution for
> "please, Git, ignore these changes".

Neither of these is an acceptable option.  Here's an entry from the FAQ,
which I have referred to several times (on StackOverflow and elsewhere):

How do I ignore changes to a tracked file?

  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.

There's no option to do this and you should adopt a different approach.
Probably 95% of the circumstances I see where people are trying to
ignore tracked files can be done by moving the original file to another
path and using a script to copy and modify the file to an ignored path.
-- 
brian m. carlson (he/him or they/them)
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