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

Request: refuse to commit .gitattributes unless the change also commits correct line endings

From
PSPaul Salmon <paul.b.salmon@gmail.com>
Date
May 10, 2015, 00:57 UTC
Message-ID
<CA+nXY9ZfeNAmLcwvYyigKAPtWg9i_0xAiKVAvUCcGZ6OXAfv_g@mail.gmail.com>

When .gitattributes is updated to mark that certain files must contain certain line endings, those files become "due" for an update. But git allows .gitattributes to be committed without updating those files to match. In fact, it won't even tell the committer that they've just made some files "stale" in this way.

The problem is that when there are files that are pending such a line endings update, git behaves very badly. In particular, one gets modified files that absolutely cannot be reverted, and (a much worse problem) some merges become impossible: you start with a clean checkout, run a merge, and then git decides that your checkout wasn't clean after all.

The solution is simple: commit a change that fixes all the line endings. But until this is done, the repo is pretty broken.

REQUEST

Don't let the repo get into this state in the first place. Or at least not without a "--force" flag.

Basically, if a commit contains a .gitattributes change, I'd like git to check whether any files that were previously OK have become "due" for a newline fix.

If so, Git should error out, explaining that the developer should also commit fixed newlines at the same time. Or if the developer insists that they want to break everything, use --force.

MOTIVATION

I recently tried to submit a few pull requests to someone else's repository that had this problem. First I went through the infuriating experience of figuring out why git was being so weird (I'm not a _complete_ git noob but this was totally new to me). Then I found myself unable to actually make any contributions. I imagine it's OK if you're the owner, but pull requests require merges from time to time, and I was almost always prevented from merging things.

On top of this, I had to convince the repo owner that his repo required a change (a 200 kLOC change!). I wasn't even sure I was right to begin with. In fact I still wonder if I got it totally wrong and you guys are going to tell me how dumb I am being.

Paul
Message 1 of 1 in “Request: refuse to commit .gitattributes unless the change also commits correct line endings”
  1. Paul SalmonMay 10, 2015

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.