:title: TIL: Navigating History with Magit :date: 2025-02-27 :tags: blog, emacs, magit :identifier: 20250222T125328 TIL: Navigating History with Magit ================================== .. highlight:: none .. container:: post-teaser Building on :denote:link:`my previous discovery <20250221T190247>`, today I figured out a few ways of exploring the history of a project with ``magit``. `This issue `__ provided a nice motivating example to have in mind - the ``exceptiongroup`` Python package was dropped from a ``requirements.txt`` file - in which commit did it happen? From ``magit-dispatch`` ----------------------- From any file in the repository you can - Invoke ``magit-dispatch`` (:kbd:`C-x M-g`) - Open the log menu (:kbd:`l`) - Limit the log to commits affecting a specific file (:kbd:`--`) and enter the filename(s) at the minibuffer prompt (``code/requirements-libs.txt``) in my case - Generate the log for the current branch (:kbd:`l`) Which resulted in the following buffer:: Commits in develop touching code/requirements-libs.txt a0b08399 * build(deps): bump websockets from 14.1 to 14.2 in /code d781cdc0 * code: Update dependencies f88f8ad5 * build(deps): bump tomli from 2.0.2 to 2.2.1 in /code 83e810c6 * code: Update bundled dependencies d6462b20 * code: Bundle a basic Sphinx env with the extension Then with point on one of the commits, hitting :kbd:`SPC` will open the corresponding diff in a new window:: commit d781cdc0 limited to file code/requirements-libs.txt d781cdc087a1846ecc13df36d6ee4b6ad383a3b9 Author: Alex Carney AuthorDate: Sat Jan 18 20:57:09 2025 +0000 Commit: Alex Carney CommitDate: Thu Jan 23 19:56:08 2025 +0000 Parent: 19be4d6b devenv: Use `uv` for dependency resolution Contained: develop release Follows: esbonio-vscode-extension-v0.96.1 (9) Precedes: esbonio-language-server-v1.0.0b10 (32) code: Update dependencies 1 file changed, 5 insertions(+), 9 deletions(-) code/requirements-libs.txt | 14 +++++--------- modified code/requirements-libs.txt @@ -1,16 +1,12 @@ -# -# This file is autogenerated by pip-compile with Python 3.9 -# by the following command: -# -# pip-compile --generate-hashes --output-file=requirements-libs.txt requirements-libs.in -# +# This file was autogenerated by uv via the following command: +# uv pip compile --prerelease=allow --generate-hashes --python-version 3.9 --output-file requirements-libs.txt requirements-libs.in aiosqlite==0.20.0 \ --hash=sha256:36a1deaca0cac40ebe32aac9977a6e2bbc7f5189f23f4a54d5908986729e5bd6 \ --hash=sha256:6d35c8c256637f4672f843c31021464090805bf925385ac39473fb16eaaca3d7 # via -r requirements-libs.in -attrs==24.2.0 \ - --hash=sha256:5cfb1b9148b5b086569baec03f20d7b6bf3bcacc9a42bebf87ffaaca362f6346 \ - --hash=sha256:81921eb96de3191c8258c199618104dd27ac608d9366f5e35d011eae1867ede2 +attrs==24.3.0 \ + --hash=sha256:8f5c07333d543103541ba7be0e2ce16eeee8130cb0b3f9238ab904ce1e85baff \ + --hash=sha256:ac96cd038792094f438ad1f6ff80837353805ac950cd2aa0e0625ef19850c308 # via # cattrs # lsprotocol [back] However, the ``magit-log:`` buffer will still be focused - it turns out navigating up and down the list with :kbd:`n` and :kbd:`p` will automatically refresh the diff to match the new commit under point! From ``magit-file-dispatch`` ---------------------------- A perhaps faster way to acheive the same result is to - Navigate to the file of interest ``code/requirements-libs.txt`` - Invoke ``magit-file-dispatch`` (:kbd:`C-c M-g`) - Select log (:kbd:`l`) Navigating history ------------------ Another nice set of commands in the ``magit-file-dispatch`` menu are in the ``Navigate`` column:: File actions Inspect Navigate More actions s Stage D Diff... L Log... B Blame... p Prev blob c Commit u Unstage d Diff l Log b Blame n Next blob e Edit line , x Untrack t Trace m Blame echo v Goto blob , r Rename V Goto file , k Delete g Goto status , c Checkout G Goto magit Using :kbd:`n` or :kbd:`p` you can walk through the history of the current file, or if you know the commit/branch/tag, jump to it directly with :kbd:`v`. Then if you wish you can view the diff for the current revision with :kbd:`d`. Now I wonder if it's possible to integrate :kbd:`n` and :kbd:`p` with `repeat-mode `__... 🤔