When using VC for a Git repository on Emacs 24.3, I want to view commits in a different branch from the one I've checked out.

It seems like C-u C-x v l should be command for that, as it asks Log from revision (default: last revision):, but if I enter origin/master, the *vc-change-log* buffer still shows the revision history of the currently checked out branch, just as if I had used plain C-x v l.

Is there a way to get VC to show the change log for a different branch, or do I need to stick with M-! git log HEAD..origin/master?

  • Thank you for the retrospective bounty, legoscia. Very nice of you, and I'm glad you found the answer so useful.
    – phils
    Apr 11 '16 at 20:51
  • Yes, I use your function at least once a week. Thanks again :)
    – legoscia
    Apr 12 '16 at 9:05

Looks like you'll need to be calling vc-print-log-internal with the IS-START-REVISION argument. e.g.:

(vc-print-log-internal 'Git '("/var/www/CHANGELOG.txt") "origin/master" t 2000)

You could make a modified variant of vc-print-log to provide a command to do this, if there's nothing which does this already? (and I'm not seeing anything myself).

(defun my-vc-print-revision-log (working-revision &optional limit)
  "List the change log at WORKING-REVISION of the current fileset in a window.

If LIMIT is non-nil, it should be a number specifying the maximum
number of revisions to show; the default is `vc-log-show-limit'.

When called interactively with a prefix argument, prompts for LIMIT also."
   (let ((rev (read-from-minibuffer
               "Working revision (default: last revision): " nil nil nil nil))
         (lim (when current-prefix-arg
                (string-to-number (read-from-minibuffer
                                   "Limit display (unlimited: 0): "
                                   (format "%s" vc-log-show-limit)
                                   nil nil nil)))))
     (when (string= rev "") (setq rev nil))
     (when (and lim (<= lim 0)) (setq lim nil))
     (list rev lim)))
  (let* ((vc-fileset (vc-deduce-fileset t)) ;FIXME: Why t? --Stef
         (backend (car vc-fileset))
         (files (cadr vc-fileset)))
    (vc-print-log-internal backend files working-revision t limit)))
  • M-x report-emacs-bug perhaps? I'd think this would be a useful addition, despite not all backends supporting the argument in question.
    – phils
    Feb 16 '16 at 1:47

I don't know for VC, but for magit, there is magit-log-ranged which should do what you want.

  • 1
    Since v2.1 that is no longer the case. Now a multi-line log is automatically used when an argument is used that requires that (--path, --stat, and/or ++header).
    – tarsius
    Dec 18 '15 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.