git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: .gitignore is not enough

From
AZAleem Zaki <aleemzaki@gmail.com>
Date
Aug 3, 2023, 21:47 UTC
Message-ID
<BAFA1866-33FE-461C-812A-5E4232D40EAA@gmail.com>
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?
Show 54 quoted lines
> 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
Previous: brian m. carlson
Message 8 of 8 in “.gitignore is not enough”
  1. Aleem ZakiAug 3, 2023
  2. Hilco WijbengaAug 3, 2023
  3. Johannes SixtAug 3, 2023
  4. Hilco WijbengaAug 3, 2023
  5. Johannes SixtAug 3, 2023
  6. Junio C HamanoAug 3, 2023
  7. brian m. carlsonAug 3, 2023
  8. Aleem ZakiAug 3, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.