I have a git repository located in ~/Desktop/ML/Books
. In this repo, I've made a series of edits to a file (main.rs
) as follows:
When I open VS Code (using, for example, the command
code ProgrammingRust/projs/actix-gcd/src/main.rs
) and click the "Open Changes" button, I see a visual side-by-side comparison of the file’s staged content versus the latest edits in the working copy.
I've configured my global git settings (in ~/.gitconfig
) to use VS Code as my difftool.
However, when I run the command:
git difftool ProgrammingRust/projs/actix-gcd/src/main.rs
instead of showing a comparison between the staged and unstaged versions, it compares the current file with an unexpected "unknown" file (as seen in the attached screenshot of paths).
What I need is to automate this diff view – that is, have a single terminal command (or a small set of commands) that directly opens the VS Code side-by-side diff view comparing the staged version of main.rs
against its working copy without any extra clicks in the GUI.
How can I configure or invoke git difftool
(or another command) to achieve this behavior?
Fixed it by adding --wait
argument to the command in the .gitconfig
file (or ./.git/config
file for local change). Like:
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
Then running the following command:
git difftool --no-prompt --tool=vscode ProgrammingRust/projs/actix-gcd/src/main.rs