TIL: Navigating History with Magit

From magit-dispatch

From any file in the repository you can

  • Invoke magit-dispatch (C-x M-g)

  • Open the log menu (l)

  • Limit the log to commits affecting a specific file (--) and enter the filename(s) at the minibuffer prompt (code/requirements-libs.txt) in my case

  • Generate the log for the current branch (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 SPC will open the corresponding diff in a new window:

commit d781cdc0 limited to file code/requirements-libs.txt
d781cdc087a1846ecc13df36d6ee4b6ad383a3b9
Author:     Alex Carney <alcarneyme@gmail.com>
AuthorDate: Sat Jan 18 20:57:09 2025 +0000
Commit:     Alex Carney <alex.rugby101@gmail.com>
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 n and 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 (C-c M-g)

  • Select log (l)