I know I can use git difftool
with the --dir-diff
option in order to compare all the files in one go.
But using difftool
with prompt has its use (for a reasonably small number of files to diff), especially since git 1.7.8, where you can skip a file.
However, that prompt doesn't show how many files are in the diff queue or how many has already been diff'ed.
How would you display that information in the difftool
prompt?
git difftool is a Git command that allows you to compare and edit files between revisions using common diff tools. git difftool is a frontend to git diff and accepts the same options and arguments. See git-diff [1].
Valid values include emerge, kompare, meld, and vimdiff. Run git difftool --tool-help for the list of valid <tool> settings. If a diff tool is not specified, git difftool will use the configuration variable diff.tool. If the configuration variable diff.tool is not set, git difftool will pick a suitable default.
This tutorial will discuss, with examples, the basics of diffing with Git and how to use the git diff command. By the end of reading this tutorial, you’ll be an expert at using the git diff command. The git diff command displays the differences between files in two commits or between a commit and your current repository.
By executing the git diff command, we can see the differences between these two files. By default, the git diff command produces a diff for all files between the latest commit and the current state of the repository. When we run the command, the following response is returned:
With git alone, you can't (git 1.8.x).
But that feature is coming (in Git 1.9/2.0 Q1 2014)
See commit 6904f9a from Zoltan Klinger's patch.
When
--prompt
option is set,git-difftool
displays a prompt for each modified file to be viewed in an external diff program. At that point it could be useful to display a counter and the total number of files in the diff queue.Below is the current difftool prompt for the first of 5 modified files:
Viewing: 'diff.c'
Launch 'vimdiff' [Y/n]:
Consider the modified prompt:
Viewing (1/5): 'diff.c'
Launch 'vimdiff' [Y/n]:
The current
GIT_EXTERNAL_DIFF
mechanism does not tell the number of paths in the diff queue nor the current counter.
To make this "counter/total
" info available forGIT_EXTERNAL_DIFF
programs without breaking existing ones:
- Modify
run_external_diff()
function indiff.c
to set one environment variable for a counter and one for the total number of files in the diff queue.
The size of the diff queue is already available in thediff_queue_struct
.
For the counter define a new variable in thediff_options
struct and reset it to zero indiff_setup_done()
function.
Pre-increment the counter inside therun_external_diff()
function.- Modify
git-difftool--helper.sh
script to display the counter and the diff queue count values in thedifftool
prompt.
That results in:
git-difftool--helper.sh @@ launch_merge_tool () {
# the user with the real $MERGED name before launching $merge_tool.
if should_prompt
then
printf "\nViewing (%s/%s): '%s'\n" "$GIT_DIFF_PATH_COUNTER" \
"$GIT_DIFF_PATH_TOTAL" "$MERGED"
if use_ext_cmd
then
printf "Launch '%s' [Y/n]: " \
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With