Programing

emacs의 파일에 계속 나타나는 ^ M은 무엇입니까?

lottogame 2020. 6. 17. 20:25
반응형

emacs의 파일에 계속 나타나는 ^ M은 무엇입니까?


따라서 텍스트 메이트와 관련이 있다고 생각하지만 소규모 팀에서 일하고 있으며 한 분기의 각 줄에 ^ M이 추가되어 git에서 거의 동일한 파일의 전체 파일 충돌과 관련된 문제가 있습니다.

이 신비한 ^M인물 은 무엇 을해야하며 어디에서 왔을까요?

우리 개발자들은 Windows / Mac에서는 emacs, Mac에서는 TextMate, Mac에서는 coda, 때로는 wp-admin 텍스트 편집기를 사용합니다.

이 문제가 그 중 하나에서 비롯된 적이 있습니까?


누군가 줄 끝 문자를 올바르게 변환하지 않습니다 .

CRLF를 좋아하는 Windows 사람들이라고 생각합니다. Unix는 LF를 좋아하고 Mac은 Unix 방식을 보여줄 때까지 CR을 좋아했습니다.


에서 자식-설정 , 설정 core.autocrlf하는 true자식은 자동으로, 예를 들어 플랫폼에 대해 올바르게 라인 엔딩을 변환 전역 설정에 대해이 명령을 실행하기 위해 :

git config --global core.autocrlf true

^M되어 0x0d, 캐리지 리턴 문자를 즉. 디스플레이가 다음과 같은 경우

라인 1 ^ M
2 호선

Windows의 표준 줄 바꿈 순서는 CR LF( 0x0d 0x0a) 인 반면 표준 줄 바꿈 순서는 LFUnices 로만 구성 되므로 파일은 Windows 에서 가져와야합니다.

파일이 Mac OS 9 또는 이전 시스템에서 제공된 경우 다음과 같이 표시됩니다.

라인 1 ^ 라인 2 ^ M

캐리지 리턴 다음에 줄 바꿈이 없기 때문입니다.


^ M을 git에서 사라지게하려면 다음을 입력하십시오.

git config --global core.whitespace cr-at-eol

크레딧 : https://lostechies.com/keithdahlby/2011/04/06/windows-git-tip-hide-carriage-return-in-diff/


그들은 DOS 스타일 라인 엔딩과 유닉스 스타일의 차이점과 관련이 있습니다. Wikipedia 기사를 확인 하십시오 . 도움이되는 dos2unix 도구를 찾거나 작은 스크립트를 작성하여 스스로 해결할 수 있습니다.

편집 : 여기 에서 다음 Python 샘플 코드를 찾았습니다 .

string.replace( str, '\r', '' )

query-replace 대신 Mx delete-trailing-whitespace를 사용할 수도 있습니다.


내가 사용하고 안드로이드 스튜디오 (JetBrains의 인 IntelliJ의 IDEA )에 맥 OS를 내 문제는 ^ M이 내 풀 요청에 일부 파일에 표시하기 시작했다 GitHub의 . 나를 위해 일한 것은 파일의 줄 구분 기호를 변경하는 것이 었습니다.

편집기에서 원하는 파일을 열고 이동을 파일 로 이동 라인 구분은 다음 당신을위한 최고의 옵션을 선택 (나를 위해 그것이 LF - 유닉스와 OS X (\ n) )

다음 기사에 따르면이 문제는 운영 체제 간의 혼란스러운 줄 끝으로 인한 결과입니다. http://jonathonstaff.com/blog/issues-with-line-endings/

자세한 내용은 https://www.jetbrains.com/help/idea/configuring-line-separators.html#d84378e48를 참조 하십시오.

여기에 이미지 설명을 입력하십시오


당신의 ~/.emacs(또는 등가)에 다음을 냄비

(defun dos2unix ()
  "Replace DOS eolns CR LF with Unix eolns CR"
  (interactive)
    (goto-char (point-min))
      (while (search-forward "\r" nil t) (replace-match "")))

그런 다음 간단히 사용할 수 있습니다 M-x dos2unix.


^M at the end of line in Emacs is indicating a carriage return (\r) followed by a line feed (\n). You'll often see this if one person edits files on Windows (where end of line is the combination of carriage return and newline characters) and you edit in Unix or Linux (where end of line is only a newline character).

The combination of characters is usually not harmful. If you're using source control, you may be able to configure the text file checkin format so that lines are magically adjusted for you. Alternatively, you may be able to use checkin and checkout triggers that will automatically "fix" the files for you. Or, you might just use a tool like dos2unix to manually adjust things.


As everyone has mentioned. It's different line ending style. MacOSX uses Unix line endings - i.e. LF (line feed).

Windows uses both CR (carriage return) & LF (line feed) as a line ending. Since you're using both windows and mac thats where the problem stems from.

If you create a file in windows and then bring it onto the mac you might see these ^M characters at the end of the lines.

If you want to remove them you can do this very easily in emacs. Just highlight and copy the ^M character and do a query-replace ^M with and you'e done.

EDIT: Some other links that may be of help. http://xahlee.org/emacs/emacs_adv_tips.html

This one helps you configure emacs to use a particular type of line-ending style. http://www.emacswiki.org/emacs/EndOfLineTips


I ran into this issue a while back. The ^M represents a Carriage Return, and searching on Ctrl-Q Ctrl-M (This creates a literal ^M) will allow you get a handle on this character within Emacs. I did something along these lines:

M-x replace-string [ENTER] C-q C-m [ENTER] \n [ENTER]

See also:

Hiding ^M in emacs

Be careful if you choose to remove the ^M characters and resubmit to your team. They may see a file without carriage returns afterward.


If you don't have dos2unix utility installed on your system, you can create your own to get rid of Windows endline characters:

vi ~/dos2unix.bash:

with the following content

#!/bin/bash
tr -d '\r' < $1 > repl.tmp
mv -f repl.tmp $1

In your ~/.bashrc, add the line:

alias 'dos2unix=~/dos2unix.bash'

Applying

dos2unix file_from_PC.txt

will remove ^M characters at lines ends in file_from_PC.txt. You can check if you have those or not by using cat:

cat -v file_from_PC.txt

The solution for me was to use the following elisp function found in this Emacs Wiki Article.

 (defun dos2unix ()
      "Not exactly but it's easier to remember"
      (interactive)
      (set-buffer-file-coding-system 'unix 't) )

M-x dos2unix버퍼 에서 기능 실행하고 파일을 저장하면 모두 ^M사라집니다.

참고 URL : https://stackoverflow.com/questions/1822849/what-are-these-ms-that-keep-showing-up-in-my-files-in-emacs

반응형