39

I have branch where I have one commit that only modifies whitespace (trailing whitespace and leading whitespace).

I ran git rebase master and git rebase --ignore-whitespace master and in both cases I have a merge conflict with the commit that only changed whitespace.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
jcubic
  • 61,973
  • 54
  • 229
  • 402

2 Answers2

60

I can't guarantee that this will help, but you could try
git rebase -Xignore-space-change master
or
git rebase -Xignore-all-space master.
-X passes options into the merge algorithm, and the default merge algorithm has these options to affect how it handles whitespace.

Rob Bednark
  • 25,981
  • 23
  • 80
  • 125
Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
  • 2
    but see http://stackoverflow.com/questions/16598538/need-git-rebase-xignore-all-space-to-preserve-my-space – Martin Popel Aug 27 '15 at 08:25
  • I am having trouble determining what the difference is between `-Xignore-space-change` and `-Xignore-all-space` ... seems like for most projects there are plenty of languages that are space-sensitive. It would be useful to ignore whitespace changes for only certain file extensions... –  Sep 11 '18 at 03:13
  • 1
    The git command fails when ran as `git rebase -Xignore-all-space --continue`. – Hi-Angel Mar 09 '19 at 20:16
  • `git pull -Xignore-all-space origin master --rebase` runs but still throws conflicts on white space diffs, presumably end of line stuff... – Robin Nelson Apr 01 '21 at 16:32
9

This is easier with Git 2.29 (Q4 2020)

"git rebase -i"(man) learns a bit more options, including --ignore-whitespace on merge (which was not supported in 2014 when the OP used that option).

So git rebase --ignore-whitespace master will now work!

See commit 6160b2e (26 Aug 2020) by Junio C Hamano (gitster).
See commit 2712669 (17 Aug 2020), and commit ef484ad (13 Jul 2020) by Rohit Ashiwal (r1walz).
See commit a3894aa, commit 7573cec, commit e8cbe21 (17 Aug 2020) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 9c31b19, 03 Sep 2020)

rebase -i: add --ignore-whitespace flag

Signed-off-by: Rohit Ashiwal
Signed-off-by: Phillip Wood

Rebase is implemented with two different backends - 'apply' and 'merge' each of which support a different set of options.

In particular the apply backend supports a number of options implemented by 'git am(man) ' that are not implemented in the merge backend.

This means that the available options are different depending on which backend is used which is confusing.

This patch adds support for the --ignore-whitespace option to the merge backend.
This option treats lines with only whitespace changes as unchanged and is implemented in the merge backend by translating it to -Xignore-space-change.

git rebase now includes in its man page:

--ignore-whitespace:

Ignore whitespace differences when trying to reconcile differences.
Currently, each backend implements an approximation of this behavior:

apply backend: When applying a patch, ignore changes in whitespace in context lines. Unfortunately, this means that if the "old" lines being replaced by the patch differ only in whitespace from the existing file, you will get a merge conflict instead of a successful patch application.

merge backend: Treat lines with only whitespace changes as unchanged when merging.
Unfortunately, this means that any patch hunks that were intended to modify whitespace and nothing else will be dropped, even if the other side had no changes that conflicted.

This flag is passed to the 'git apply' program

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250