Is it possible to change the line break used by git to something other than the default \n (e.g. a period . or period plus whitespace)?
I am asking because this would make it easier to use git to manage text files such as documentation and markdown files. I have seen articles suggesting people to put each sentence in its own line just so that it is treated as one unit by git (rather than a part of a longer paragraph), which is awkward. Hence the question here.
I did some internet search to no avail.
interesting idea! But sorry, no.
I upvoted your question because I love the idea. Unfortunately the answer is: No, Git does not support this.
As stated in the git config documentation, the valid values for
core.eolarelfandcrlf:Other related git config settings are
core.safecrlfandcore.autocrlf. gitattributes documentation also says the same.why git is unlikely to ever support this
lfandcfare control characters with very specific meaning. Regular characters such as period.have many meanings depending on the context. In many langauges it marks the end of a sentence. But it means something different in numbers....is often used to be an ellipses, which is not three sentence endings.So git supporting such an option would result in a mess for many text files stored in a git repo.
a workaround: use a git commit
hookto automatically insertlfafter every period in your text file that doesn't have one.It would be a pretty simple regular expression to do that.
By trying this approach you will discover one of two things:
(a) Cool, it works for me! And my files are still normal text files and my repo is still normal so other people can use it.
(b) Wow, now I know why they don't support this. What a #$*&#@CRLF mess!
why you really don't need this
The reason there are "articles suggesting people to put each sentence in its own line" is because
git diffused to support only line granularity diffs. Line diffs work great for code but suck for prose. Inserting a sentence or even editing one word results in the whole paragraph being marked as changed unless the paragraph is broken up into lines.But
git diffnow supports word granularity if you use the--word-diff[=<mode>],--word-diff-regex=<regex>or--color-words[=<regex>]option.Type
git help diffor see git-diff Documentation for more info.