--- title: Log date: 2023-11-07T12:34:39+00:00 tags: git identifier: 20231107T123439 --- # `git log` ## Find a deleted file in history If you don't know the full path [Source](https://stackoverflow.com/questions/7203515/how-to-find-a-deleted-file-in-the-project-commit-history) ``` git log --all --full-history -- "**/name.*" ``` If you know the path ``` git log --all --full-history -- ``` ## 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 [Source](https://stackoverflow.com/questions/19987099/how-do-i-view-all-commits-for-a-specific-day) ``` git log --after="2013-11-12 00:00" --before="2013-11-12 23:59" ``` ## List all commits affecting a specific file ``` git log --follow -- ``` Here `—follow` instructs git to also track renames. To also include the diff with each commit ``` git log -p -- ``` [Stack Overflow](https://stackoverflow.com/questions/3701404/how-to-list-all-commits-that-changed-a-specific-file) ## List all the files that ever existed ``` git log --pretty=format: --name-only --diff-filter=A | sort -u ``` [Stack Overflow](https://stackoverflow.com/questions/543346/list-all-the-files-that-ever-existed-in-a-git-repository) ## Trace the evolution of a function ``` git log -L :func_name:path/to/file.py ``` This relies on the same mechanism that {denote:link}`20231107T123925` uses to determine a patch's hunk header. See {ref}`20231107T123925-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