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

The current Git-based project I'm working on, I'm usually always in a subdirectory.

Below is the output when I run the git log -name-only command from the subdirectory of the repository root.

commit 678bd5ba6fc5474c4c61406768bf6cba5937c5d1
Author: thegreendroid
Date:   Mon Mar 27 09:36:24 2017 +1300

    Commit message

 child_dir1_from_root/file1                     |  184 +--
 child_dir2_from_root/file2                     |    2 +-

      

How do I get git log to output something like below instead? This makes it easier to iterate over files by simply copying the file path and running git diff HEAD ~ {copied_file_path} instead of having to manually change the file path and then running the command.

commit 678bd5ba6fc5474c4c61406768bf6cba5937c5d1
Author: thegreendroid
Date:   Mon Mar 27 09:36:24 2017 +1300

    Commit message

 file1                                          |  184 +--
 ../child_dir2_from_root/file2                  |    2 +-

      

I looked at the git log documentation but nothing stood out. I can write a script to do this, but I was curious if git has a built-in way?

+3


source to share


2 answers


To use paths in the output git log --name-only

, add an option --git-dir

to git diff

.

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

      

For ease of use, create 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

can now work as long as the current directory belongs to the working tree.

+3


source


You can add - relative = 'PATH' to your desired subdirectory.



+1


source







All Articles