问题
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:
- Make sure PyCharm is running.
- 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.
- Outside of PyCharm, add the path and name of the launcher script to your path.
On Windows:
- 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