liximomo / vscode-sftp

Super fast sftp/ftp extension for VS Code
MIT License
1.5k stars 260 forks source link

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

Open ulavar opened 6 years ago

ulavar commented 6 years ago

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

liximomo commented 6 years ago

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

ulavar commented 6 years ago

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

xNinjaKittyx commented 5 years ago

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

necmettin commented 5 years ago

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.

iaeiou commented 2 years ago

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

oscarjb commented 2 years ago

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

zhyiyu commented 2 years ago

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

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