Magit and Forge

Diff a PR

Using forge

From the status buffer (not the View Topic buffer!):

  • ' f f to fetch all topics
  • n down to the PR listing
  • d d (diff dwim) on the PR listing

This will do a between origin/main...refs/pullreqs/<PR number>.

This doesn't work if you're actually visiting the PR topic (i.e. you hit Enter on the PR listing and are now in a View Topic buffer).

I really want the diff-dwim to work from the View Topic buffer - is there some way to get that working?

Using branch names without checking out

From any magit buffer:

  • d r to diff a range
  • type in: origin/main...pullreqs/<PR number>

It would be nice if this was the default dwim behavior in a PR topic buffer.

Using current branch

  • Check out the PR (if you are using forge, you can do b f)
  • d r (magit-diff-range)
  • Type in: main... (or master...)

See this StackOverflow for an explanation of the git diff main... command. It's basically the "do that thing that I obviosly always want to do" command, which is to diff HEAD with main, ignoring extra stuff on main.

Rebase and move branch pointers

Do the rebase. The same commits will have different SHAs. Old branches will still be at previous SHAs.

  • Go to logs buffer
  • For each branch:
    • check out branch
    • move cursor to commit where branch should be moved to
    • x to reset to this commit

View file history

  • M-x magit-log-buffer-file

View previous version of a file

The function magit-find-file is to "View FILE from REV". Running M-x magit-find-file will first prompt for a revision (completes with a list of all refs), then prompts for a file.

From a specific file:

  • M-x magit-log-buffer-file
  • Move to the commit you want
  • M-x magit-find-file

Visit File from Diff

Just press <return> on a chunk in the diff. Buuut, if you want it to use another window:

(use-package magit
  :bind
  (:map magit-diff-mode-map
        ("M-<return>" . magit-diff-visit-file-other-window)))

View Current and Previous File Version from Diff

  • In diff, <return> to visit the file
  • M-x magit-find-file-other-window, branch, <RET>

Cherry pick

A A. I always forget about this.