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

git add without whitespace

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
May 30, 2016, 15:26 UTC
Message-ID
<CAHd499Agn=vLBxDpHi2dy1HMy-_58PZGs7VNtFJnBfP5zXatTA@mail.gmail.com>

I think it would be useful to have a '-w' option for 'git add' that completely ignores whitespace changes, the same way that 'git diff -w' does.

Real life scenario:

Sometimes developers will use tooling that does not properly strip trailing whitespace in source files. Next time I edit those files for a simple 1-line code change, my tooling will strip whitespace from the whole file. I *do* want these changes, however I want 2 commits: 1 commit with the bugfix, and a supplementary commit with just the whitespace changes.

At the moment, there is no way for me to conveniently add the source file to the index without whitespace. The only way to accomplish this today that I'm aware of is via this command:

$ git diff -U0 -w --no-color | git apply --cached --ignore-whitespace --unidiff-zero

This command explicitly leaves out context because it can sometimes cause the patch to fail to apply, I think due to whitespace being in it, but I'm not completely sure myself.

It would be useful to be able to do this instead:
$ git add -w

This would effectively function the same as my workaround command shown earlier. It should also be valid to use -w with -i and -p. In the -p case, it just won't show hunks containing whitespace changes. For -i, it would assume '-w' as part of any command run during the interactive session.

Does this idea sound good? I have some free time on my hands so I wouldn't mind implementing this. Maybe there isn't a huge audience for this kind of thing, or maybe I'm just going about this the wrong way. Thoughts would be much appreciated.

Next: Junio C Hamano
Message 1 of 8 in “git add without whitespace”
  1. Robert DaileyMay 30, 2016
  2. Junio C HamanoMay 30, 2016
  3. Robert DaileyMay 30, 2016
  4. Junio C HamanoMay 30, 2016
  5. Robert DaileyMay 31, 2016
  6. Junio C HamanoMay 31, 2016
  7. Christian NeukirchenMay 31, 2016
  8. demerphqMay 31, 2016

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.