服务器之间同步代码_如何在多个设备和环境之间同步VS代码设置

服务器之间同步代码

All developers like their text editor a certain way, but it can be tough to make sure all of your environments have the same configuration. How can we make sure our VS Code configuration is the same wherever we use it?

所有开发人员都以某种方式喜欢他们的文本编辑器,但是要确保所有环境都具有相同的配置可能很困难。 我们如何确保我们的VS Code配置在任何地方都相同?

什么是VS代码? (What is VS Code?)

Visual Studio Code, or VS Code, is an all-inclusive code editor that takes all of the features you want out of working with code and puts them in one editor to make you ultra productive.

Visual Studio Code或VS Code是一种功能全面的代码编辑器,它可以利用代码中不需要的所有功能,并将它们放在一个编辑器中,以提高工作效率。

It’s been the “cool kid on the block” for a little while now and has been increasingly growing in popularity at least in the JavaScript community. Microsoft has put a lot of effort into making it something people want to use (and they’re doing a great job at that).

一段时间以来,它一直是“块子上的好孩子”,并且至少在JavaScript社区中,它越来越受欢迎。 微软付出了很多努力使它成为人们想要使用的东西(他们在这方面做得很好)。

我们将使用什么? (What will we use?)

We’re going to use a VS Code extension called Settings Sync that makes use of Github’s Gist feature to store a private JSON configuration file in the cloud.

我们将使用一个名为Settings Sync的VS Code扩展,该扩展利用Github的Gist功能将私有JSON配置文件存储在云中。

它是如何工作的? (How does it work?)

The extension uses Github’s OAuth to log in to your Github account. Once approved, VS Code obtains an access token and reaches out to both store and download your settings file to a private Github Gist.

该扩展程序使用Github的OAuth登录到您的Github帐户。 一旦获得批准,VS Code便会获得访问令牌,并可以将您的设置文件存储和下载到私有的Github Gist。

Once it’s set up, you can then configure the extension on any other instance of VS Code and immediately download your configuration to sync up your editor.

设置完成后,您便可以在VS Code的任何其他实例上配置扩展,并立即下载配置以同步编辑器。

步骤0:VS代码 (Step 0: VS Code)

We’ll assume for this walkthrough you have VS Code already installed. While you don’t need to have any special configuration, having something different than the default (like a color theme) will help you see it work.

在本演练中,我们假设您已经安装了VS Code。 尽管您不需要任何特殊的配置,但与默认设置(例如颜色主题 )不同的内容将帮助您看到它的工作。

Let’s get started!

让我们开始吧!

步骤1:安装设置同步 (Step 1: Install Settings Sync)

The first thing we need to do is install the extension. You can do this a few ways — you can visit the webpage and hit Install which will open up VS Code or you can search for the extension in the Extensions panel.

我们需要做的第一件事是安装扩展。 您可以通过几种方式执行此操作-您可以访问网页并点击“ 安装” ,这将打开VS Code,或者您可以在“扩展”面板中搜索扩展。

Once installed, it will open up a new tab with the Settings Sync dashboard.

安装完成后,它将使用“设置同步”信息中心打开一个新标签。

第2步:授权访问Github (Step 2: Authorize access to Github)

To get started with Github, click the Login with Github button in the Settings Sync dashboard.

要开始使用Github,请在“设置同步”控制台中单击“ 使用Github登录”按钮。

This will open up Github in your default web browser and ask you to log in. While you can use any Github account you want, it would probably make most sense to use your personal account.

这将在您的默认Web浏览器中打开Github,并要求您登录。虽然您可以使用所需的任何Github帐户,但使用个人帐户可能最有意义。

Once you’re logged in, you should now see Success! in your browser.

登录后,您现在应该看到成功! 在您的浏览器中。

第3步:上传当前设置 (Step 3: Upload your current settings)

Now that you’re connected to Github, you’re ready to upload your settings.

现在,您已经连接到Github,就可以上传设置了。

Open up your Command Palette with CMD+Shift+P (on Mac) or navigate to View and Command Palette. Type “Sync Upload” which will filter the commands and hit enter once the Sync: Update/Upload Settings option is selected.

使用CMD + Shift + P(在Mac上)打开命令面板 ,或导航到“视图和命令面板”。 键入“同步上传”,它将过滤命令并在选择“ 同步:更新/上传设置”选项后按Enter。

When doing this, you might be prompted with screen that asks if you want to force upload — press Yes.

执行此操作时,系统可能会提示您询问是否要强制上传-按

At this point, Settings Sync will create a new Gist in your Github account with your configuration settings. Once it’s done you should see a success message.

此时,“设置同步”将使用您的配置设置在您的Github帐户中创建一个新的Gist。 完成后,您应该会看到一条成功消息。

You should now be able to visit gist.github.com and find a new private cloudSettings Gist that includes all of your VS Code settings!

您现在应该可以访问gist.github.com并找到一个包含所有VS Code设置的新的私有cloudSettings Gist!

步骤4:将您的配置同步到另一个环境 (Step 4: Syncing your configuration to another environment)

To sync your VS Code configuration to another computer or VS Code environment, you want to first follow steps 1 and 2 above — installing the extension and logging in to Github.

要将VS Code配置同步到另一台计算机或VS Code环境,您要首先按照上述步骤1和2进行操作-安装扩展程序并登录到Github。

The difference is this time, you’ll want to configure VS Code to download your settings instead of upload them.

这次是不同的,您需要配置VS Code以下载设置,而不是上传设置。

To get started, first open back up your Sync Settings dashboard. If this is a new installation like we’re assuming here, you can open up the Command Palette and type “sync download” and hit enter which will open up that dashboard. Here, click Edit Configuration this time.

首先,请先备份“同步设置”信息中心。 如果这是我们此处假设的新安装,则可以打开“命令面板”并键入“ sync download”,然后按Enter键将打开该仪表板。 在这里,这次单击“ 编辑配置”

On this screen, you should see your Github Access Token, but you should also see an empty field for Gist ID. Here, we want to first grab the ID from our cloudSettings Gist URL:

在此屏幕上,您应该看到您的Github访问令牌 ,但您还应该看到Gist ID的空白字段。 在这里,我们要首先从cloudSettings Gist URL中获取ID:

And then paste that value inside of our Gist ID input in VS Code.

然后将该值粘贴到VS Code中的Gist ID输入中。

Once it’s there, you can open the Command Palette again, type “sync download”, and hit enter, and Sync Settings will fetch your VS Code configuration from the Gist and update your local settings with that configuration!

到达该位置后,您可以再次打开命令面板,键入“ sync download”,然后按Enter,然后Sync Settings将从Gist中获取您的VS Code配置并使用该配置更新您的本地设置!

步骤5:更新您的配置 (Step 5: Updating your configuration)

From here on, any time you want to make a new change to your stored configuration, you’ll want to use both the Update/Upload and Download features like we used above.

从这里开始,每当您要对存储的配置进行新的更改时,都将需要使用我们上面使用的更新/上传和下载功能。

To update a new tweak to your configuration, type “sync update”  and hit enter:

要为您的配置更新新的调整,请输入“同步更新”,然后按Enter:

And to download your configuration to sync up another editor, type “sync download” and hit enter:

要下载您的配置以同步另一个编辑器,请键入“ sync download”,然后按Enter:

These commands will both update your cloudSettings Gist and download from it to sync up your VS Code instances

这些命令将更新您的cloudSettings Gist并从中下载以同步VS Code实例

您最喜欢的VS Code技巧是什么? (What’s your favorite VS Code trick?)

Share it with me on Twitter!

在Twitter上与我分享!

加入对话 (Join the conversation)

翻译自: https://www.freecodecamp.org/news/how-to-sync-vs-code-settings-between-multiple-devices-and-environments/

服务器之间同步代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值