On most teletypes, CR and LF do just what their names imply: carriage return returns the carriage carrying the paper to the right, so the hammers or type head are above the left of the page or equivalently, it returns the type head to the left of the page, depending on which part of the assembly is mobile , and line feed feeds the page one line up. The order was important: carriage return takes some time to execute, so starting it first meant that the line feed would happen in parallel to the carriage return, and by the time the line feed was processed, the carriage had a decent chance of having finished, so the next character could be processed safely otherwise it ended up smeared across part of the page as the carriage finished flying back.
Unix was inspired by Multics, whose developers chose LF as the line-ending character, relying on device drivers to translate that to whatever character sequence was required on actual devices.
LF is defined as. The objective of typewriter device independence also has some implications for control characters. The Multics strategy here is to choose a small subset of the possible control characters, give them precise meanings, and attempt to honor those meanings on every device, by interpretation if necessary. I recall discussions on this topic where the idea was floated that the Multics developers did this in order to save disk space, which seems incorrect given the above.
That ended up not being sufficient, and Unix stty allows users to choose one of several CR durations. Devices receiving a CR would advance to the start of the next line, and lines were delineated with just a CR.
An LF might behave identically, or might advance to the same spot on the next line, but it wouldn't usually matter because LF codes weren't used much. This approach allowed arbitrary binary graphic data to be included within files to printed. Devices receiving an LF would advance to the start of the next line, while receipt of a CR would reset them to the start of the current line.
Lines were delineated with LF; CR would generally only be used if necessary to overprint the current line. Devices receiving an CR would reset to the start of the current line, and devices receiving an LF would either advance to the start of the next line or the current position on the next line.
This approach would be prone to malfunction when printing files containing binary graphics data. Approach 4 was used by the Apple II among others; approach 5 was used by Unix. When the PC came out, however, many popular printers including the Epson MX, were configurable to process CR and LF using approach 1 or 3, but not 2, and they also handled bitmap graphics with a command that would take a specified number of bytes as binary pixel data that needed to sent verbatim even if it contained the bit patterns or The fact that printers would have problems with 2, 4, or 5 meant that the if MS-DOS wanted to be suitable for use with such printers it would need to adopt approach 1 or 3.
Of those choices, 1 is slightly more efficient but 3 offers more efficient overprinting. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Learn more. What does CRLF mean? Asked 11 years ago. Active 2 years, 4 months ago. Viewed 52k times. Improve this question. Peter Mortensen 2, 5 5 gold badges 23 23 silver badges 24 24 bronze badges. Cripes, I read that as "someone texted me crlf" hence the close vote. Nice interpretation, Farseeker. What is newline character in C?
A newline is a character used to represent the end of a line of text and the beginning of a new line. In programming languages, such as C, Java, and Perl, the newline character is represented as a ' ' escape sequence.
A newline is not the same as a carriage return. You should use this for files that must keep LF endings, even on Windows. What is Autocrlf in git? It takes a single argument. On OS X, you simply pass input to the configuration. How do I use Git? The easiest way to get started is to create an account on GitHub.
Step 2: Create a new repository. Not good. Fortunately, there's a better solution: creating a. Git reads this file and applies its rules whenever you check out or commit files, ensuring that your line ending conventions are enforced regardless of how each individual developer has configured git locally or what OS they're using. I've provided a condensed summary below. First, you need to understand that git uses a simple algorithm to detect whether a particular file in your repo is a text file or a binary file e.
By default, this algorithm is used for the purpose of diffing files that have changed, but it can also come in handy for the purpose of enforcing line ending conventions as we're doing here. This should work well on both Windows and Linux since a majority of cross-platform text editors support LF. But as I mentioned earlier, historically, some Windows text editors like Notepad would struggle to interpret LF alone.
Nowadays, this is less of a problem. Git's auto-detection algorithm is fairly accurate, but in case it fails to correctly distinguish between a text file and a binary file like an image or font file , we can also explicitly mark a subset of our files as binary files to avoid bricking them. That's what we're doing here:. Now, after committing this file, the final step is to renormalize all your line endings for any files that were checked into git prior to the addition of. You can do that with the following command since git 2.
This reformats all your files according to the rules defined in your. If previously committed files are using CRLF in git's index and are converted to LF as a result of this renormalization, their line endings will be updated in the index, and those files will be staged for a commit.
The only thing left to do is to commit those changes and push them to your repo. From that point onward, anytime a new file is introduced, its line endings will be checked in and checked out as LF.
This is the expected behavior— CRLF will become LF in Git's index, meaning when you push those files to your repo, they'll have LF line endings in the remote copy of your code. Anyone who later pulls or checks out that code will see LF line endings locally. But git doesn't actually change line endings for the local copies of your files i.
Hence the last bit of the message, which informs you that the files you just renormalized may still continue to use CRLF locally. Rest assured that these files will never use CRLF in the remote copy of your code if you've specified LF as your desired line ending convention in the.
If you want to double-check that the files in Git's index are using the correct line endings after all of these steps, you can run the following command:. This will show you line ending information for all files that git is tracking, in a format like this:.
Alternatively, you can double-check that git normalized your line endings correctly by re-cloning your repository on a Windows machine after you've pushed your code to the remote. You should see that both the index and working-tree copies of your files are using LF and not CRLF assuming this is how you chose to normalize your line endings. However, as we saw above, you may still see CRLF line endings locally for files that you created because.
Again, this doesn't mean that git's normalization process isn't working; it's just the expected behavior. However, this can get annoying if you're also linting your code with ESLint and Prettier, in which case they'll constantly throw errors and tell you to delete those extra CR s:. Fortunately, you can take things a step further with an. Lots of text editors including VS Code support and automatically read this file if it's present. You can put something like this in the root of your workspace:.
In addition to a bunch of other settings, you can specify the line ending that should be used for any new files created through this text editor. That way, if you're on Windows using VS Code and you create a new file, you'll always see line endings as LF in your working tree.
0コメント