Here's my preference: view the change history visually in meld, one commit at a time, going backwards in time, starting at commit commit
:
# Option 1: for all files and folders
git difft commit
# Option 2: just for the specified files and folders
git difft commit -- path/to/file.c path/to/folder/
I wrote git difft
. Installation instructions are below.
How to manually view the change history of a file graphically in meld
If you want to just see which commits changed a file, so you can do git difftool
on them to graphically see the changes with meld
(as I explain here), do this instead:
git log --follow --oneline -- path/to/file.c
Sample run and output:
eRCaGuy_hello_world$ git log --follow --oneline -- c/alsa_aplay__play_tone_sound_WIP.c
04b67fb (HEAD -> master) Update c/alsa_aplay__play_tone_sound_WIP.c
301122a wip: alsa_aplay__play_tone_sound.c: finish initial version of program
d4e8092 wip: add c/alsa_aplay__play_tone_sound.c
Now I can just look at the last changes graphically in meld
like this (pulling the commit hashes from the output above).
Note that I intentionally leave off the filename so that it can properly track the file automatically for me since the file was renamed, and I know these commits likely only edited this file anyway:
# just the last change
git difftool 04b67fb~..04b67fb
# and the one before that
git difftool 301122a~..301122a
# ...and before that
git difftool d4e8092~..d4e8092
If you need to specify the filename, just do so with:
git difftool 04b67fb~..04b67fb -- path/to/file.c
[Recommended] How to automatically view the changes, one commit at a time, in meld, using git difft
Install meld
as your git difftool
, per my instructions.
Install my git difft
wrapper from my eRCaGuy_dotfiles repo.
In Linux, it runs in the terminal. In Windows, it runs in the Git Bash terminal which comes with Git for Windows.
Installation instructions, as modified from my git diffn
installation instructions here, are:
mkdir -p ~/bin
cd ~/bin
curl -LO https://raw.githubusercontent.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/master/useful_scripts/git-difft.sh
chmod +x git-diffn.sh
mv git-diffn.sh git-diffn
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
. ~/.bashrc
See also the instructions in the top of the git-difft.sh
file.
Usage:
# Look at changes from just one commit at at time, going backwards from the
# current commit
git difft
# Look at changes starting from commit `commit`
git difft commit
You can also specify a set of files or folders to track, like this:
git difft commit -- path/to/file.c path/to/folder/
git difft commit -- path/to/file1 path/to/file2 path/to/file3
git difft -- path/to/some/dir
# etc/
Press Ctrl + C, then Enter to skip the current commit and go to the next one back in time.
Or, press Ctrl + C twice to exit the program.
Here is the full help menu, as shown by git difft -h
:
'git-difft' version 0.2.0
Iterate through all commits going backwards from HEAD to the first commit, one commit at a time,
running 'git difftool' on each one to see the changes it introduced.
- Press Ctrl + C once, then Enter, to break out of the current 'git difftool' command, but continue
on with the previous commit.
- Press Ctrl + C twice to exit out of the whole program.
USAGE:
git-difft [OPTIONS] [[commit] [commit_start~..commit_end]] -- [file1 file2 file3 ...]
OPTIONS
-h, -?
Print help menu
-v, --version
Print version information.
--
Lists of files or directories go after this point.
EXAMPLE USAGES:
git-difft -h
Print help menu.
git-difft
Start running 'git difftool' on the commit starting at HEAD (the currently-checked-out
commit).
git-difft HEAD
Same as above.
git-difft HEAD~
Start running 'git difftool' on the commit starting at HEAD~ (one before HEAD).
git-difft HEAD~2
Start running 'git difftool' on the commit starting at HEAD~2 (two before HEAD).
git-difft abcdefg
Start running 'git difftool' on commit hash abcdefg.
git-difft my_branch
Start running 'git difftool' on the commit at the tip of branch 'my_branch'.
git-difft commit1~..commit2
Run 'git difftool' on all commits between commit1 and commit2, inclusive.
git-difft commit1..commit2
Run 'git difftool' on all commits between commit1 and commit2, including commit2 but
NOT including commit1.
git-difft commit1~..commit2 -- file1 file2 file3
Run 'git difftool' on all commits between commit1 and commit2, inclusive, but only
for the files file1, file2, and file3.
git-difft -- path/to/file1
Start running 'git difftool' on the commit starting at HEAD, but only for the file
"path/to/file1".
git-difft -- path/to/dir1
Start running 'git difftool' on the commit starting at HEAD, but only for the files
in the directory "path/to/dir1/".
This program is part of eRCaGuy_dotfiles: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles
by Gabriel Staples.