git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aleem Zaki <aleemzaki@gmail.com>
To: "brian m. carlson" <sandals@crustytoothpaste.net>
Cc: Johannes Sixt <j6t@kdbg.org>,
	Hilco Wijbenga <hilco.wijbenga@gmail.com>,
	git@vger.kernel.org
Subject: Re: .gitignore is not enough
Date: Thu, 3 Aug 2023 14:47:53 -0700	[thread overview]
Message-ID: <BAFA1866-33FE-461C-812A-5E4232D40EAA@gmail.com> (raw)
In-Reply-To: <ZMweZHQZL7nnla+2@tapette.crustytoothpaste.net>

I understand, I shall copy the empty config and paste into a new ignored file where I then add my personal customizations. 

What if, however, all git commands besides ‘git pull’ and ‘git fetch’, are able to modify the files in question. Would we then have a potential new git feature?

> On Aug 3, 2023, at 2:38 PM, brian m. carlson <sandals@crustytoothpaste.net> wrote:
> 
> 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

      reply	other threads:[~2023-08-03 21:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03  3:23 .gitignore is not enough Aleem Zaki
2023-08-03  5:35 ` Hilco Wijbenga
2023-08-03 17:17   ` Johannes Sixt
2023-08-03 17:49     ` Hilco Wijbenga
2023-08-03 20:27       ` Johannes Sixt
2023-08-03 21:53         ` Junio C Hamano
2023-08-03 21:38     ` brian m. carlson
2023-08-03 21:47       ` Aleem Zaki [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=BAFA1866-33FE-461C-812A-5E4232D40EAA@gmail.com \
    --to=aleemzaki@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=hilco.wijbenga@gmail.com \
    --cc=j6t@kdbg.org \
    --cc=sandals@crustytoothpaste.net \
    /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).