Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PyCharm as a GIT diff tool from the command line?

On the PyCharm Help Website I see you can use PyCharm as a diff tool from the Command Line to compare two files. That's awesome! However is there a way to take it a step further and use it as a git diff tool.

So I can just type pycharm diff file_name.py and get the GIT differences same way you would if you were on PyCharm have setup the GIT integration and press CTRL + D to see the differences.

like image 768
Dimo Avatar asked Nov 18 '15 12:11

Dimo


People also ask

How to see diff in PyCharm?

To open the Diff & Merge page, open settings by pressing Ctrl+Alt+S and navigate to Tools | Diff & Merge. Click this button to scroll both differences panes simultaneously.

How do I get Git status in PyCharm?

PyCharm lets you review the state of your project at a selected revision. Open the Git tool window Alt+9 and switch to the Log tab. Select a commit and choose Show Repository at Revision from the context menu.


1 Answers

Yes you can.

First you need to enable the command-line launcher:

To enable invoking PyCharm operations from the command line, follow these steps

  • On macOS or UNIX:

    1. Make sure PyCharm is running.
    2. On the main menu, choose Tools | Create Command-line Launcher. The dialog box Create Launcher Script opens, with the suggested path and name of the launcher script. You can accept default, or specify your own path. Make notice of it, as you'll need it later.
    3. Outside of PyCharm, add the path and name of the launcher script to your path.
  • On Windows:

    1. Specify the location of the PyCharm executable in the Path system environment variable. In this case, you will be able to invoke the PyCharm executable and other PyCharm commands from any directory.

https://www.jetbrains.com/help/pycharm/running-pycharm-as-a-diff-or-merge-command-line-tool.html

Then add the following lines to your ~/.gitconfig:

[diff]
        tool = pycharm
[difftool "pycharm"]
        cmd = /usr/local/bin/charm diff "$LOCAL" "$REMOTE" && echo "Press enter to continue..." && read
[merge]
        tool = pycharm
[mergetool "pycharm"]
        cmd = /usr/local/bin/charm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
        keepBackup = false

(for Windows users these details might be slightly different)

like image 198
Anentropic Avatar answered Oct 07 '22 01:10

Anentropic