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

Re: git add without whitespace

From
RDRobert Dailey <rcdailey.lists@gmail.com>
Date
May 30, 2016, 19:50 UTC
Message-ID
<CAHd499Drdt6GoScdksNNWLrsvG3Dex7fTYNhatL-qboCPW5RZQ@mail.gmail.com>
In-Reply-To
<xmqqlh2r8ixu.fsf@gitster.mtv.corp.google.com>
On Mon, May 30, 2016 at 2:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> I have had this in my ~/.gitconfig for a long time.
>
> [alias]
>         wsadd = "!sh -c 'git diff -- \"$@\" | git apply --cached --whitespace=fix;\
>                 git co -- ${1-.} \"$@\"' -"
>
> That is, "take what's different from the _index_ and the working
> tree, apply that difference while correcting whitespace errors to
> the index, and check the result out to the working tree".  This
> would _not_ touch existing whitespace-damaged lines that you are not
> touching, and honours the customized definition of what is
> considered whitespace breakage for each paths (which you set up with
> the attributes system).
>

I like your solution better than mine because it utilizes the rules defined in .gitattributes. I think that's a really good idea. But other than that, yours is functionally the same as what I'm doing, right? I just want to make sure I understand: What ends up in the index/staging area is the code MINUS the trailing whitespace (e.g. whitespace errors)?

What does the checkout at the end do? That part confuses me (granted I'm not well-versed with bash script).

Thanks for the feedback. Looks like this is niche enough that an alias/script is probably the best solution.

Previous: Junio C HamanoNext: Junio C Hamano
Message 3 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.