vscode-sftp icon indicating copy to clipboard operation
vscode-sftp copied to clipboard

Control M characters (^M) are getting added, at the line end

Open ulavar opened this issue 7 years ago • 7 comments

Expected Behavior

import os import sys import shutil import glob

Actual Behavior

import os^M import sys^M import shutil^M import glob^M

Steps to Reproduce the Problem

  1. Transfer any file to remote linux machine from windows client (VS code)
  2. After uploading the file , go to remote linux machine and open the file with vi editor
  3. At the end of each line, you can see ^M being added.

Usually this happens SFTP tranferred from windows to Unix. These characters need to be ripped off before uploaded. There is a utility called dos2unix, FYI

Requisites

Extension Logs

[set option sftp.printDebugLog to true, then reload vscode, reproduce the problem, get the logs(view -> output-> sftp)]

Specifications

  • Version: sftp:0.6.7
  • Platform: Windows 10 client, Ubuntu 16.XX remote

ulavar avatar Oct 05 '17 16:10 ulavar

I'm sorry. You should strip the ^M character yourself. This extension just transfers files.

liximomo avatar Oct 08 '17 08:10 liximomo

I got a solution to my problem. Anyways, Thanks!!

ulavar avatar Oct 08 '17 12:10 ulavar

If anyone was curious about this question (in 2019) and you are using Windows VSCode, with a Linux remote & you're using git.

This works best if your repository is consistently using LF.

Windows git needs to be reconfigured to not automatically convert your local repos to CRLF

git config --global core.eol lf
git config --global core.autocrlf input

This way, when code comes in, it'll not be converted to CRLF, but when you check code in, it'll be guaranteed to be LF.

Then you need to refresh your repository. (If you have uncommitted changes, you might want to back them up, or push upstream. The --cached should not delete them, but if you want to be extra careful).

git rm -rf --cached .
git reset --hard HEAD

Where I got some info from: https://stackoverflow.com/a/33424884/3648890

xNinjaKittyx avatar Jan 15 '19 20:01 xNinjaKittyx

I got a solution to my problem. Anyways, Thanks!!

It would be nice if you cloud explain the solution to this problem.

A little theoretical knowledge, you are running Windows, and the server is Linux. Windows uses CRLF (which corresponds to chr(10)chr(13), which is Ctrl+J Ctrl+M; and that is why you are seeing whose ^M characters.

The culprit is, almost always, Git. (Well, the other possibility is generally the editor, but VSCode does not have that behavior, so..)

Thanks @xNinjaKittyx for the solution.

necmettin avatar Feb 03 '19 08:02 necmettin

I had the same issue, and found this extension to display actual end of lines (to adapt my setup to the actual project):

https://marketplace.visualstudio.com/items?itemName=medo64.render-crlf

iaeiou avatar Dec 06 '21 01:12 iaeiou

I got a solution by changing the carriage return (CRLF in windows) to (LF) for line ending.

  1. I used the command palette (shift+crtl+p) then I selected the option "Change End Of Line sequence"
  2. Select LF

Furthermore, you can install the "Render Line Endings" to check the changes

oscarjb avatar Jul 05 '22 10:07 oscarjb

I found this solution which ignores the difference between carriage return:

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

zhyiyu avatar Aug 14 '22 12:08 zhyiyu