Setting Sublime Text For Git In Mac

  1. Sublime Text Git Integration
  2. Setting Sublime Text For Git In Machine
  3. Sublime Text Editor For Mac

Git is a very popular version control system and Sublime Text is very popular text editor tool. If you are new to sublime text editor then I recommend you to read Sublime Text Plugins, Tips and Settings.This post explains step by step on how to use Git plugin into Sublime Text editor to increase development productivity.

Active11 months ago

When I do a git diff in my branch I see that line endings have the characters ^M:

I want to replace these with Unix line endings before committing my changes.

I am using Ubuntu 14.04, git and sublime text 3.

Thanks for your help.

EDIT:

I am looking for a way to change line endings in sublime text 3 not using other utilities or commands.

Achraf JEDAY
Achraf JEDAYAchraf JEDAY
4081 gold badge5 silver badges12 bronze badges

5 Answers

You can use dos2unix command in linux (package dos2unix) or change line endings in Sublime Text under menu item View / Line Endings.

Jan ČejkaJan Čejka

This can be done without a plugin via the menu at the top or though the statusbar (but you need to enable the feature).

Sublime Text Git Integration

To change it through the menu at the top click View -> Line Endings -> Select desired line ending type.

To enable this through the status bar:Click Preferences -> SettingsThen add 'show_line_endings': true, somewhere between the {} brackets on the right-hand side.Finally, save your changes.

This enables a small section on the right of the status bar that shows up at the bottom. It tells you the current EOL encoding and by clicking the box and selecting a different type it changes the files EOL character for you.

Another helpful option is file encoding which can be enabled in the statusbar as well by following the same setups above but also adding 'show_encoding': true, between the {} marks.

K.B.K.B.

^M is r (Control-M, or carriage return).

This is likely because the user who committed the file was using windows, which uses rn for its line endings. Linux uses only n, hence you see the ^M at the end of the line.

You probably want to do one of the following:

  • 'Fix' the file to have n line endings (using a tool such as dos2unix) and commit. In which case you'll be fighting with the other user unless you can get them to do the below.
  • Configure both of your git installations to handle line endings correctly for each environment - e.g: https://stackoverflow.com/questions/10418975/how-to-change-line-ending-settings
  • Configure Sublime to open the file with 'Windows line endings'
AttieAttie
13.8k4 gold badges37 silver badges52 bronze badges

I found a sublime text plugin that converts line endings in all open files to Unix/Windows/Mac OS 9.

Installation

  1. Open Sublime and go to Preferences > Browse Packages. This will opena window.
  2. Download or clone the contents of this repository to a folder namedexactly as the package name into the Packages/ folder you opened in the previous step:

/home/YOUR_USERNAME/.config/sublime-text-3/Packages

Usage

  1. Go back to sublime and open all the files that you want to convert.
  2. Once all of the files are open hit CTRL + SHIFT + P, and search andselect “Line Ending to all view: Unix”.
  3. Hit CTRL + ALT + S to save all of the open files.
Achraf JEDAYAchraf JEDAY
4081 gold badge5 silver badges12 bronze badges

To whom may not want to install additional plugin to remove ^M new lines,

  1. In sublime text setting, add 'trim_trailing_white_space_on_save': true, to auto remove space when saving. (This step might be optional)

  2. On the file you are opening, click right bottom corner of sublime text. Change Windows to Unix and save.

  1. ^M is gone. Enjoy.
harrrrrrryharrrrrrry

Not the answer you're looking for? Browse other questions tagged gitubuntu-14.04sublime-text-3 or ask your own question.

Active7 months ago

I have a problem setting Sublime Text 2 as the core.editor with git.

I've read through every post I could find addressing the problem, but still nothing is working for me. I am running Windows.

I have done:

and tried that with various arguments like -m. When I open my .gitconfig, this is what is in there:

If I go to Git and type:

the README file opens in Notepad, not Sublime Text.

Does anyone have any idea what I'm doing wrong or how I could fix this?

Spencer MoranSpencer Moran
1,0952 gold badges9 silver badges12 bronze badges

15 Answers

Windows

Sublime Text 2 (Build 2181)

The latest Build 2181 just added support for the -w (wait) command line argument. The following configuration will allow ST2 to work as your default git editor on Windows. This will allow git to open ST2 for commit messages and such.

Sublime Text 3 (Build 3065)

Sublime Text 3 (Build 3065) added the subl.exe command line helper. Use subl.exe -h for the options available to you. I have hot_exit: true and remember_open_files: true set in my Sublime Text user settings. I have found the following to git config to work well for me.

Mac

Mac and Linux

Set Sublime as your editor for Git by typing the following command in the terminal:

git config --global core.editor 'subl -n -w'

With this Git config, the new tab is opened in my editor. I edit my commit message, save the tab (Ctrl+S) and close it (Ctrl+W).

Git will wait until the tab is closed to continue its work.

chicks
1,6632 gold badges16 silver badges31 bronze badges
jrotellojrotello
3,8811 gold badge16 silver badges15 bronze badges
fedorqui
182k57 gold badges377 silver badges420 bronze badges
sfufoetsfufoet

For Mac OS X in the file ~/.gitconfig under [core] I had to put this code to solve the issue on my end.

This was when subl was working fine but git was unable to access it. And was displaying these errors

GutterAhmad AwaisAhmad Awais
14k3 gold badges49 silver badges43 bronze badges

For Mac & Sublime Text 3:

If git config --global core.editor 'subl -n -w' doesn't work, use this git config command:

Note: it does not contain escaping backslashes.

nu-bonu-bo

what worked for me in cygwin/zsh:

in /usr/local/bin create subl_git file

in gitconfig:

meeechmeeech

With Sublime Text 2 and the following configuration, if nothing happens when you close the git commit's comment file :

If the git commit doesn't finish when you close the COMMIT_EDITMSG comment file in Sublime, I've found this is probably because you are running CMD in administrator mode (and have a Sublime Text already opened in non admin mode). I had the same problem and it worked for me when I started my CMD in normal mode.

Ps : just wanted to answer to the problem @david pointed out in the accepted answer's comments, but I couldn't post comment since I'm new here... so I've made a new answer, because I think this can be useful to some people encountering the problem.

FrancoisFrancois

I just successfully made it with the help of PowerShell (command line tools for windows, which is also be use as the default command line on GithubforWindows)

Just make a folder 'WindowsPowerShell' on 'C:Users%username%My Documents'.Then, create a file called 'profile.ps1'.Make sure that you have the correct file extension, .ps1 and not .txt.inside the profile.ps1, put this line to set an alias command:

Make sure the sublime directory on your machine is correct.You can also see the configuration details in here.

Now, I can edit files with Sublime Text 2 via PowerShell command just by typing:

Setting Sublime Text For Git In Machine

Hopefully this is usefull...

rwinzhangrwinzhang

I've faced the same problem with git editor in Windows this evening, and finally I've got it.

You'll need to set your editor path with the bash syntax and using the DOS 8.3 format to avoid spaces:

This doesn't work (for me):

This do:

You can get the DOS 8.3 name for a directory with dir /x

Diego BuendiaDiego Buendia

I was just struggling with this for some reason, none of the examples above quite worked for me. This was my solution however:

You specifically need the ' ' around the path and the $* at the end of the args, all in ' '.

justin.m.chasejustin.m.chase
8,5505 gold badges34 silver badges73 bronze badges
mainframermainframer
9,2898 gold badges35 silver badges57 bronze badges
Sublime text 3 download mac

well, i had some trouble invoking notepad++ from gitbash even after setting it as my core.editor.

i got it all solved by appending the below line to my .bashrc file in my gitbash installation directory.

so, i can invoke notepad++ with the alias 'npp'. i feel this can help you if you change the directory to the respective editor you want to use.

OLATOMIDEOLATOMIDE

For MAC Users I can say for Sublime use the following:

First Check the .gitconfig file using command:

  1. cd ~
  2. ls -la
  3. cat .gitconfig

Now one can add this configuration:

Where l1 will tell to start at line 1.

fedorqui
182k57 gold badges377 silver badges420 bronze badges
bvmCoderbvmCoder

For Windows 7 I have found the following solution works:

tscott1tscott1

On Windows, if you are installing git, you can select other editor and give the following command line.C:Program FilesSublime Text 3sublime_text.exe -w

Xavier JohnXavier John
3,9283 gold badges20 silver badges27 bronze badges

I haven't seen any instances of updates regarding Windows allowing Git installation to actively pick Sublime Text as your default text editor without all the sturm und drang of the original override codes...

AngelfirenzeAngelfirenze

Sublime Text Editor For Mac

Not the answer you're looking for? Browse other questions tagged giteditordefaultsublimetextgit-config or ask your own question.