0

after pushing the code on my git repository there is ^M character showing after end of the each line in the file.How can i remove these character from there.

here is the screenshot of the code which is on git [1]: https://i.stack.imgur.com/7T3A5.png

i used few solutions suggested by others like--

git config --global core.autocrlf true

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

these solutions is not helpful for me.If you have any other way to resolve it please suggest me for that.

bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • 1
    Don't use Windows. Add a prehook script to remove `\r` from the files (on Windows). Best of luck. – Elliott Frisch Apr 25 '21 at 16:45
  • 2
    Does this answer your question? [What are these ^M's that keep showing up in my files in emacs?](https://stackoverflow.com/questions/1822849/what-are-these-ms-that-keep-showing-up-in-my-files-in-emacs) – sanjeevRm Apr 25 '21 at 16:55
  • @sanjeevRm I suspect that many developers don't even know what "emacs" is these days. The title of that question is not conducive to following through in the context of a Git problem. – Ed Randall Apr 25 '21 at 17:53
  • This is probably the best existing answer: [What's the best CRLF (carriage return, line feed) handling strategy with Git?](https://stackoverflow.com/questions/170961/whats-the-best-crlf-carriage-return-line-feed-handling-strategy-with-git) – Ed Randall Apr 25 '21 at 19:07

1 Answers1

-1

Git has this "feature" of auto-converting line endings for your local platform. Some of my projects build files for both Windows and Unix platforms - those outputs need to be correct for their targets, irrespective of what platform is doing the build. Therefore I prefer to prevent it from doing any conversion and have the files always unchanged. Modern text editors can render different line endings without a problem and I don't want my version control messing with my files.

You need to do all of the following steps:

First, the line-end changing behaviour must be disabled with:

git config --global core.autocrlf=false

Second, to keep the files correct in future (and before you check-in the "fixed" files), check-in a .gitattributes file in the root of your project something like this:

*.bat           text eol=crlf
*.cmd           text eol=crlf
*.properties    text eol=lf
*.pl            text eol=lf
*.py            text eol=lf

Finally, you need to fix the incorrect local files. Convert the line endings to LF with:

dos2unix filename

or to CRLF with

unix2dos filename

(use the git-bash shell if on windows). Then check them in.

Ed Randall
  • 6,887
  • 2
  • 50
  • 45