How to make git log show file paths relative to current directory?

In order to use the paths in the output of git log --name-only, add the option --git-dir to git diff.

git --git-dir="$(git rev-parse --show-toplevel)"/.git diff HEAD~ child_dir1_from_root/file1

For easy use, make an alias in the config.

[alias]
        mdiff = "! git --git-dir=\"$(git rev-parse --show-toplevel)\"/.git diff"

git mdiff HEAD~ child_dir1_from_root/file1 now can work as long as the current directory belongs to the working tree.


You can add up the --relative='PATH' to the subdirectory you want.