Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open git diff in sublime from command line

How can I open a git diff in sublime from the terminal?

like image 314
tnrich Avatar asked Feb 20 '15 08:02

tnrich


People also ask

How do I see git diff in terminal?

You can run the below commands to compare the changes for specific file: git diff HEAD <file_name> git diff <file_name>

Does Sublime Text have git integration?

Sublime Merge IntegrationThe Git features available in Sublime Text were derived from work that went into our other product, Sublime Merge. Sublime Merge is a full-featured, blazing-fast Git client built upon the technologies from Sublime Text.

How does git diff command work?

Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

How do I add Git to Sublime Text?

Install Git Plugin in Sublime Text In your text editor, open package installer using Cmd + Shift + P on Mac or Ctrl + Shift + P on windows. Go to Install Package -> Git. After successful installation, your can access commands of Git plugin using Cmd + Shift + P on mac and Ctrl + Shift + P on windows machine and type Git:.

How do I open a file in Sublime Text?

Dev4.03.23.13.0 Sublime Text includes a command line tool, subl, to work with files on the command line. This can be used to open files and projects in Sublime Text, as well working as an EDITORfor unix tools, such as git and subversion. Setup Windows Mac Linux Usage Configuring as EDITOR Setup

Does Sublime Text have a command line tool?

Dev4.03.23.13.0 Sublime Text includes a command line tool, subl, to work with files on the command line. This can be used to open files and projects in Sublime Text, as well working as an EDITORfor unix tools, such as git and subversion.

How to add a new file in git diff?

By default entries added by "git add -N" appear as an existing empty file in "git diff" and a new file in "git diff --cached". This option makes the entry appear as a new file in "git diff" and non-existent in "git diff --cached".


Video Answer


1 Answers

First, make sure you have the subl command accessible from the command line: Open Sublime Text from Terminal in macOS

Next, in your .profile or .bashrc or wherever you keep your aliases, add:

#open diff in sublime. 
#ex: gd   
#ex: gd head^   
#ex: gd 7b3f441147f7c3c4b27bb7c9658aef27e3d0a5eb ee49bbc57f7376bc9f5c951e13808cb6b66be3d8
gd() {
    if [ $# -eq 0 ]
        then
            git diff | subl
        else
            git diff $@ | subl
    fi
}

And you can now open your diffs in sublime right from your terminal.

like image 101
tnrich Avatar answered Oct 16 '22 03:10

tnrich