View a file's history in Magit?

GitEmacsMagit

Git Problem Overview


https://stackoverflow.com/questions/278192/view-the-change-history-of-a-file-using-git-versioning talks about other ways of viewing history of a file in Git.

Can it be done in Emacs Magit?

Git Solutions


Solution 1 - Git

Since magit 2.1: magit-log-buffer-file (as per comment below)

Before magit 2.1: magit-file-log is what you are looking for. It will show you all commits for the file in the current buffer in the standard magit log view.

Solution 2 - Git

Open your magit-status buffer, by typing M-x magit-status (I used to have this bound to C-. C-g because it is used all the time. These days, I use Spacemacs so it's <SPC> g s)

  1. Type l to get log viewing option
  2. Type -- to set the "Limit to files" option (used to be =f)
  3. Enter the file path you wish to view history for
  4. Type l to view the log of the current branch

If you're using Spacemacs, you can get the history of the currently visited file using <SPC> g f h

Solution 3 - Git

In your *magit: <project>* buffer use l to go into logging mode, then press f to be prompted for a filename.

Solution 4 - Git

If magit (user manual) doesn't have that feature, then you can have a look at other Emacs mode, and add you own git-log-file function:

(defun git-log-file ()
  "Display a log of changes to the marked file(s)."
  (interactive)
  (let* ((files (git-marked-files))
         (buffer (apply #'git-run-command-buffer "*git-log*" "git-rev-list" \
"--pretty" "HEAD" "--" (git-get-filenames files))))  (with-current-buffer buffer
      ; (git-log-mode)  FIXME: implement log mode
      (goto-char (point-min))
      (setq buffer-read-only t))
    (display-buffer buffer)))

Solution 5 - Git

I do not know a way. I simply use M-x vc-print-log which seems to accomplish the same feat. It is not a magit-integrated way, though.

Solution 6 - Git

Hit C-cM-g to bring up the magit-file-dispatch: it has several "file-local" magit commands, such as blame and log (l).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioneugeneView Question on Stackoverflow
Solution 1 - GitRaggeView Answer on Stackoverflow
Solution 2 - GitBryan AshView Answer on Stackoverflow
Solution 3 - GitBart VandendriesscheView Answer on Stackoverflow
Solution 4 - GitVonCView Answer on Stackoverflow
Solution 5 - Gitsp3ctumView Answer on Stackoverflow
Solution 6 - GithrabanView Answer on Stackoverflow