Windows platform is on the sublime edit files on the remote Linux platform

Source: Internet
Author: User
Tags free ssh using git git commands

Sublime is a powerful cross-platform code editing tool, not much to say.
Want to use sublime to complete the code editing work for the Django site under the Linux platform to improve efficiency (originally using Vim under Linux is less efficient and suitable for editing some of the little feet).

Download sublime_text_2.0.2_x64.tar.bz2 (http://www.sublimetext.com/) under the Linux platform

Unzip using:
TAR-XJVF sublime_text_2.0.2_x64.tar.bz2
CD sublime\ text\ 2/

Perform
./sublime_text

Error
./sublime_text:/usr/lib64/libstdc++.so.6:version ' glibcxx_3.4.11 ' not found (required by./sublime_text)
./sublime_text:/usr/lib64/libstdc++.so.6:version ' glibcxx_3.4.9 ' not found (required by./sublime_text)
./sublime_text:/lib64/libc.so.6:version ' glibc_2.11 ' not found (required by./sublime_text)

The reason is that the system used is CENTOS5, the version is too low, and the C/S library version is too low.
The company's computer can not easily upgrade the library or upgrade the system, can only find another way.


Imagine one:
The code on the Linux server is pulled down on the Windows machine, edited using sublime on the Windows platform, and then re-uploaded to the Linux server.

Problem: Code editing usually requires the actual running debugging, especially the site type of code, often need to edit and immediately verify the display results. and our entire operating environment is built under the Linux platform, so that we need to first pull the code from the Linux server down the Windows platform, change a place to re-transfer back to the Linux server, test run, if there is a problem to re-edit, re-upload, test, and so on, Very cumbersome and time-consuming. Is there a better way?

Scenario Two:
Use Git on a Linux server to build a repository for your code, clone the repository on Windows, edit the code in the clone's repository using sublime, and edit the completed push command to push all submitted updates to the remote code warehouse for testing. The process, like the idea, is improved by using GIT commands to push updates to a remote Linux server instead of manually uploading the updated files to the remote server individually.

Do not know if there is a problem, first try:
Previously, a code warehouse was created on a Linux server with the location of
/var/www/site/mycitsm
Create a code repository for other machine clones directly using the. git directory in the/VAR/WWW/SITE/MYCITSM directory
sudo git remote add origin ssh://[email protected]:P ort/var/www/site/mycitsm/.git

The remote machine can then be used
git clone ssh://[email protected]:P ort/var/www/site/mycitsm/.git D:/WWW/MYCITSM
This command removes the code warehouse on the remote server from the local d:/www/mycits directory

We download and install Git-1.9.2 (Http://git-scm.com/download/win) or third party github on the Windows platform.
Clone repository:
Go to git Bash (command-line tool created after installing GIT)
$git clone Ssh://[email protected]:P ort/var/www/site/mycitsm/.git D:/WWW/MYCITSM
You may be prompted to enter a OP1 password on the remote server (if you write the local server's public key into the Authorized_keys file for the remote server, you do not need a password.) You can refer to how to set up a password-free SSH to a remote host, and the Setup method between the Windows system and the Linux system is the same as the Linux system and the Linux system. )
You may also be prompted not to find Git-upload-pack because the location of the GIT installation on the remote server is not the standard default location, just copy the tools to a standard location, or set up a soft connection in a standard location to connect to these tools. You can also specify the location of the tool in the Clone command, such as:--upload-pack/home/op1/bin/git-upload-pack.

Since then, the directory structure and contents in the remote repository have been clone into the D:/WWW/MYCITSM directory of the local Windows Server, and you can use sublime to open the directory directly to edit the internal files.

Go to the local repository in Git bash
$CD D://WWW/MYCITSM

View git status
$git status

Submit Changes
$git Add filename
$git commit-m "some text"

To push a local warehouse to a remote repository
$git push (Origin master)

Error:
remote:error:refusing to update checked out Branch:refs/heads/master
Remote:error:By default, updating the current branch in a Non-bare repository
Remote:error:is denied, because it'll make the index and work tree inconsistent
Remote:error:with What do you pushed, and would require ' git reset--hard ' to match
Remote:error:the work tree to HEAD.
Remote:error:
Remote:error:You can set ' receive.denycurrentbranch ' configuration variable to
Remote:error: ' Ignore ' or ' warn ' in the remote repository to allow pushing into
Remote:error:its Current Branch; However, this isn't recommended unless you
Remote:error:arranged to update their work tree to match the what's pushed in some
Remote:error:other.
Remote:error:
Remote:error:To squelch This message and still keep the default behaviour, set
Remote:error: ' receive.denycurrentbranch ' configuration variable to ' refuse '.
To Ssh://[email Protected]:1022/var/www/site/mycitsm/.git
! [Remote rejected] master, master (branch is currently checked out)
Error:failed to push some refs to ' ssh://[email protected]:1022/var/www/site/my
Citsm/.git '

This means that the current branch is not allowed to be updated in a non-bare repository by default, because the content pushed will cause the index and working directory tree to be inconsistent.
Although you can allow push to the current branch by setting the ' receive.denycurrentbranch ' variable value in the GIT configuration file to ignore or warn, it is not recommended unless you schedule an update to the working directory tree to match what you push.

In that case, what happens if we set up a ROM warehouse?
To the Linux server's/var/www/site/directory
Create a bare repository (refer to Http://git-scm.com/book/zh):
$ git clone--bare mycitsm mycitsm.git
The command is actually equivalent to
$ CP-RF Mycitsm/.git Mycitsm.git

Then move the warehouse to your desired location.
$sudo git remote Add origin ssh://[email protected]:P ort/var/www/site/mycitsm.git
$git clone Ssh://[email protected]:P ort/var/www/site/mycitsm.git D:/WWW/MYCITSM

Edit with Sublime, submit locally, push to remote repository. No exception was seen.
Does that mean we can test it in a remote repository?

Connecting to the Linux server into the/var/www/site/mycitsm/directory found no changes in the files inside. Oh yes, we pushed the update to the bare repository mycitsm.git on the Linux server.
Entering Mycitsm.git, there is no working directory tree (which is why ROM warehouse is called a bare warehouse), it only records the submission history information.

It took a lot of effort, which means we can't synchronize the latest local content to the Linux original repository in this way, we can only sync the change information to the relevant bare repository, and we can't get the catalog file that can be tested in the bare repository.

And both of these scenarios have a problem, that is, the file changes in the Linux server can not actively direct feedback to the Windows side, we must re-pull back the latest files to see this change.


Imagine three:
Know that Sublime has a plug-in called SFTP, you can directly open the remote machine through the file to edit, and after saving the direct synchronization to the remote machine, sounds very tempting.

Install the package management plug-in for sublime first:
Press CTRL + ' bring up the sublime console, paste the following code into the console and enter
Import Urllib2,os;
Pf= ' Package control.sublime-package ';
Ipp=sublime.installed_packages_path ();
Os.makedirs (IPP) if not os.path.exists (IPP) else None;
Open (Os.path.join (IPP,PF), ' WB '). Write (Urllib2.urlopen (' http://sublime.wbond.net/' +pf.replace (', '%20 '). Read () )

Reboot sublime, see Package control in Perferences->package settings, the installation is successful.

Installing plug-ins with the package control
Press Ctrl+shift+p to bring up the command panel
Enter install to bring up the Install Package option and enter the FTP, the drop-down list will appear some of the relevant plug-ins, select SFTP to install the line, installed after the configuration is as follows: Select the File->sftp/ftp->set in the menu bar Up Server, and then a configuration window appears as follows:

{
The TAB key would cycle through the settings when first created
Visit http://wbond.net/sublime_packages/sftp/settings for help

SFTP, FTP or FTPS
"Type": "FTP",

"Sync_down_on_open": true,
"Sync_same_age": true,

"Host": "IP",
"User": "username",
"Password": "Passowrd",
"Port": "22",

"Remote_path": "/var/www/site/mycitsm/",
"File_permissions": "664",
"Dir_permissions": "775",

"Extra_list_connections": 0,

"Connect_timeout": 30,
"KeepAlive": 120,
"Ftp_passive_mode": true,
"Ftp_obey_passive_host": false,
"Ssh_key_file": "~/.ssh/id_rsa",
"Sftp_flags": ["-F", "/path/to/ssh_config"],

"Preserve_modification_times": false,
"Remote_time_offset_in_hours": 0,
"Remote_encoding": "Utf-8",
"Remote_locale": "C",
"Allow_config_upload": false,
}

General configuration of the parameters can be
"Host": "Yourip",
"User": "YourUserName",
"Password": "YOURPASSOWRD",
"Remote_path": "Yourpath",

This method requires the remote Linux server can be connected via SFTP or FTP, but also on the remote Linux server need to run something like FTP server, many FTP server products, choose one installation configuration is OK. Installation configuration refer to the specific product.

Both the FTP server side and the sublime end of Linux are configured to view directories and files on the remote server through File->stfp/ftp/browser server, then rename directories, edit files, etc. according to the commands provided. The edited file can be synced to a remote Linux server immediately after it is saved.
The program seems to solve our problem well, but it is not perfect, we can browse to the Linux server in the sublime experience is not good, we must use a command to return the value of the first directory, the file is edited, renamed and so on. Navigating in different directories and files is inconvenient.

Is there a plan to synchronize the directories specified on the remote Linux server to Windows Local, open the Windows Local directory directly with Sublime, display a perfect directory tree, and quickly switch between folders and files for editing, And synchronize the updates to the remote server in real time?

Final Solution:
Kung Fu is a conscientious, find that there is really such a thing. Can be SSH to the remote server, a remote server directory attached to the local, remote or local changes can be real-time reaction to the other end (in fact, the two are the same location, you are editing the Linux server files). This way we simply mount the required directory on the Linux server to Windows Local and use sublime to open the directory and edit the files in the directory exactly as you would open the local directory.

This tool is called SSHFS using SSH to access the remote host, which is used by the Windows version and the Linux version to mount the remote directory on Windows and Linux respectively.

Download the tools to install the Windows version
To first install the dependency: Dokan library-->dokaninstall_0.6.0.exe (Http://dokan-dev.net/wp-content/uploads/DokanInstall_0.6.0.exe)
In the installation SSHFS itself: Win-sshfs-0.0.1.5-setup.exe (Https://win-sshfs.googlecode.com/files/win-sshfs-0.0.1.5-setup.exe)

After you start, configure the specified host, port, username, password, directory, and so on, the directory is mounted locally, and then you can use sublime's arbitrary editing.

The goal is finally reached!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.