Log¶
Find a deleted file in history¶
If you don’t know the full path
git log --all --full-history -- "**/name.*"
If you know the path
git log --all --full-history -- <filepath>
List all commits in a given time range¶
git log --after="2013-11-01" --before="2013-12-01"
If the desired range is a day or less, specify the time also
git log --after="2013-11-12 00:00" --before="2013-11-12 23:59"
List all commits affecting a specific file¶
git log --follow -- <filename>
Here —follow
instructs git to also track renames.
To also include the diff with each commit
git log -p -- <filename>
List all the files that ever existed¶
git log --pretty=format: --name-only --diff-filter=A | sort -u
Trace the evolution of a function¶
git log -L :func_name:path/to/file.py
This relies on the same mechanism that Git Diff uses to determine a patch’s hunk header. See Defining a custom hunk header for more details.
Trace the evolution of a region¶
Even more exciting is the ability to trace the evolution of an arbitrary region of text in a file! This is super useful say for watching the evolution of a CND namespace within an NVUD file
git log -L/Design_Mission/,/Design_Misson/:tests/data.nvud
Other, perhaps less useful forms of this include using absolute line numbers and offsets
git log -L10,100:path/to/file.txt # Trace lines 10-100
git log -L10,+100:path/to/file.txt # Trace line 10 and the following 100 lines
git log -L10,-20:path/to/file.txt # Trace line 10 and the preceeding 20
Or you can use a combination of the two approaches