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

天大地大妈咪最大 提交于 2020-12-02 08:17:30

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/33780083/how-to-use-pycharm-as-a-git-diff-tool-from-the-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!