Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does git commit --cleanup=whitespace do exactly?

Tags:

git

whitespace

What does 'git commit --cleanup=whitespace' do? I'm trying to test it out but I cannot figure out what the expected behaviour is (and its git documentation on it is just one line). If I add it, and someone pulls my code, will they receive a source code with zero whitespace lines in between?

like image 654
darksky Avatar asked May 15 '13 15:05

darksky


2 Answers

Nope, its just for your commit message, not for your source code.

The default mode is cleaning commentaries (lines that begin with a #) and leading and ending empty lines. whitespace mode is keeping the comments.

like image 96
cexbrayat Avatar answered Nov 03 '22 18:11

cexbrayat


There will be another alternative to whitespace with Git 1.9.x/2.0 (Q2 2014): cleanup mode "scissors".

It is introduced with commit 75df1f4 by Nguyễn Thái Ngọc Duy (pclouds), and the new git commit --cleanup documentation:

scissors

Same as whitespace, except that everything from (and including) the line

# ------------------------ >8 ------------------------

is truncated if the message is to be edited.
"#" can be customized with core.commentChar.

So you can still keep comment, and remove everything past a certain pre-defined line.


Update July 2015 Git 2.5: this scissor is now more robust.

See commit fbfa097 (09 Jun 2015) by SZEDER Gábor (szeder).
Helped-by: Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit 07528be, 24 Jun 2015)

"git commit --cleanup=scissors" was not careful enough to protect against getting fooled by a line that looked like scissors.


Update May 2019, for upcoming Git 2.22 (Q2 2019):
The list of conflicted paths shown in the editor while concluding a conflicted merge was shown above the scissors line when the clean-up mode is set to "scissors", even though it was commented out just like the list of updated paths and other information to help the user explain the merge better.

See commit 1a2b985, commit 1055997, commit d540b70, commit ca04dc9, commit f29cd86, commit 94ca361, commit b720e1e, commit 5caab8d, commit b510f0b (17 Apr 2019) by Denton Liu (Denton-L).
Helped-by: Phillip Wood (phillipwood).
See commit dc42e9a (17 Apr 2019) by Phillip Wood (phillipwood).
Helped-by: Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit b877cb4, 08 May 2019)

cherry-pick/revert: add scissors line on merge conflict

Fix a bug where the scissors line is placed after the Conflicts: section, in the case where a merge conflict occurs and commit.cleanup = scissors.

like image 28
VonC Avatar answered Nov 03 '22 19:11

VonC