Alex Carney

Mastodon
  • Blog
  • Code
  • Notes
Search
Metadata
Feb 27, 2025
  • #emacs
  • #magit
  • #til
  • Navigating History with Magit
    • From magit-dispatch
    • From magit-file-dispatch
    • Navigating history
Related Pages
My Emacs Configuration
  • Local LLMs with Ollama and gptel
  • Using git from Emacs
    • Additional magit keybindings
    • Navigating History with Magit
    • Getting the permalink URL to a line of code
  • Emacs Appearance
    • Cusomising the Emacs Modeline
    • Emacs Themes
    • Tab Bar Utilities
  • Python in Emacs
    • Using pdb from Emacs
  • Language Servers in Emacs
  • Building Emacs from Source
    • Intstalling Emacs with systemd-sysext
  • Running shells and terminals
    • Eat: Emulate a Terminal
  • IBuffer
  • Using jj from Emacs
  • Treesitter
  • Indexing Info Manuals
  • reStructuredText in Emacs
  • Emacs Completions

Navigating History with Magit¶

Building on my previous discovery, 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 (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)

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 n or p you can walk through the history of the current file, or if you know the commit/branch/tag, jump to it directly with v.

Then if you wish you can view the diff for the current revision with d.

Now I wonder if it’s possible to integrate n and p with repeat-mode… 🤔

Links
  • Page Source
  • Source Code
Built with
  • Sphinx v8.2.3
  • Feather Icons