-
Using PHPStorm for Git Diff and Merge tools (Mac)
You love git-difftool, right? Of course! You also love PHP Storm, right? Of course! This easy procedure lets you use PHP Storm as your git-difftool.
- Open a project in PHP Storm
- Click Tools » Create Command-line Launcher…
- Edit your ~/.gitconfig file:
-
12345678910[diff]tool = pstorm[difftool]prompt = false[difftool.pstorm]cmd = /usr/local/bin/pstorm diff "$LOCAL" "$REMOTE"[merge]tool = pstorm[mergetool.pstorm]cmd = /usr/local/bin/pstorm merge "$LOCAL" "$REMOTE" "$BASE" "$MERGED"
-
- Open the project in PHP Storm (see notes below)
- Open iTerm2 (or any other terminal emulator)
- Use
git difftool
as you normally would (e.g.,git difftool .htaccess
)
Observations
- If you don’t have PHPStorm open when you try to use
git difftool
it doesn’t seem to work. I need to see if I can get it to open non PHP Storm projects, and/or I need to figure out how to switch on-the-fly between vimdiff and PHP Storm as my difftool. - If you have PHP Storm open but the project itself isn’t open, “Annotate” is not available on right-click. Other functionality may be missing too. If you project is already open in PHP Storm you can annotate the diff!
Thank you to JohnAlbin for the configuration snippet above.
-
Triggers in iTerm – Watching For Specific Strings
I was recently performing a git-add in patch mode ( git add -p ) as I normally do, and realized there were a few lines I needed to make sure I didn’t commit. These lines were sandwiched between other lines that I did want to commit, and there were hundreds of changes, so it was hard to spot them. I wondered if iTerm2 had a way of highlighting or alerting when a specific word shows up in the terminal. To my surprise I found a “Triggers” section under the “Profiles » Advanced” tab in the settings for the app. iTerm2 really can do everything!
-
Automatically Stage All Deleted Files (Git)
Tab-completion is a really nice thing that we often take for granted. While working with Git I’ve found that it becomes inconvenient to stage (add for inclusion in the next commit) removed files using git rm path/to/my/file.php. Tab completion doesn’t work on paths that no longer exist, so you have to manually type the path to the deleted item. The following snippet automatically stages ALL removed files.
git ls-files -d -z | xargs -0 git rm --cached --quiet -
Using Vimdiff with Git
UPDATED: Check out “git difftool” which makes this process much cleaner (than the commands I previously had listed here). Basically, you can tell git what to use as a diff tool and it’ll let you do things like:
12Example 1: git difftool .htaccessExample 2: git difftool HEAD^^ robots.txtHere is how I tell git to use vimdiff (these settings go in ~/.gitconfig):
1234[diff]tool = vimdiff[difftool]prompt = falseHere are some helpful commands that will get you started with vimdiff.
- ctrl+w ctrl+w – switch windows
- do – diff obtain (grab from the other side)
- dp – diff put (move to the other side)
- [c – previous difference
- ]c – next difference
- :diffupdate – (updates the diff)
- :syntax off – syntax off
- zo – open folded text
- zc – close folded text
Lastly, I suggest using the peaksea colorscheme when using vimdiff. It makes it much easier to see the changes and work with them.