Next: , Previous: , Up: Miscellaneous   [Contents][Index]


8.10 Commands for Buffers Visiting Files

By default Magit defines a few global key bindings. These bindings are a compromise between providing no bindings at all and providing the better bindings I would have liked to use instead. Magit cannot provide the set of recommended bindings by default because those key sequences are strictly reserved for bindings added by the user. Also see Global Bindings and (elisp)Key Binding Conventions.

To use the recommended bindings, add this to your init file and restart Emacs.

(setq magit-define-global-key-bindings 'recommended)

If you don’t want Magit to add any bindings to the global keymap at all, add this to your init file and restart Emacs.

(setq magit-define-global-key-bindings nil)
C-c f (magit-file-dispatch)
C-c f s (magit-stage-file)
C-c f s (magit-stage-buffer-file)
C-c f u (magit-unstage-file)
C-c f u (magit-unstage-buffer-file)
C-c f , x (magit-file-untrack)
C-c f , r (magit-file-rename)
C-c f , k (magit-file-delete)
C-c f , c (magit-file-checkout)
C-c f D (magit-diff)
C-c f d (magit-diff-buffer-file)
C-c f L (magit-log)
C-c f l (magit-log-buffer-file)
C-c f t (magit-log-trace-definition)
C-c f M (magit-log-merged)
C-c f B (magit-blame)
C-c f b (magit-blame-additions)
C-c f r (magit-blame-removal)
C-c f f (magit-blame-reverse)
C-c f m (magit-blame-echo)
C-c f q (magit-blame-quit)
C-c f p (magit-blob-previous)
C-c f n (magit-blob-next)
C-c f v (magit-find-file)
C-c f V (magit-blob-visit-file)
C-c f g (magit-status-here)
C-c f G (magit-display-repository-buffer)
C-c f c (magit-commit)
C-c f e (magit-edit-line-commit)

Each of these commands is documented individually right below, alongside their default key bindings. The bindings shown above are the recommended bindings, which you can enable by following the instructions further up.

C-c M-g (magit-file-dispatch)

This transient prefix command binds the following suffix commands and displays them in a temporary buffer until a suffix is invoked.

C-c M-g s (magit-stage-file)
C-c M-g s (magit-stage-buffer-file)

Stage all changes to the file being visited in the current buffer. When not visiting a file, then the first command is used, which prompts for a file.

C-c M-g u (magit-unstage-file)
C-c M-g u (magit-unstage-buffer-file)

Unstage all changes to the file being visited in the current buffer. When not visiting a file, then the first command is used, which prompts for a file.

C-c M-g , x (magit-file-untrack)

This command untracks a file read from the user, defaulting to the visited file.

C-c M-g , r (magit-file-rename)

This command renames a file read from the user, defaulting to the visited file.

C-c M-g , k (magit-file-delete)

This command deletes a file read from the user, defaulting to the visited file.

C-c M-g , c (magit-file-checkout)

This command updates a file in the working tree and index to the contents from a revision. Both the revision and file are read from the user.

C-c M-g D (magit-diff)

This transient prefix command binds several diff suffix commands and infix arguments and displays them in a temporary buffer until a suffix is invoked. See Diffing.

This is the same command that d is bound to in Magit buffers. If this command is invoked from a file-visiting buffer, then the initial value of the option (--) that limits the diff to certain file(s) is set to the visited file.

C-c M-g d (magit-diff-buffer-file)

This command shows the diff for the file of blob that the current buffer visits.

User Option: magit-diff-buffer-file-locked

This option controls whether magit-diff-buffer-file uses a dedicated buffer. See Modes and Buffers.

C-c M-g L (magit-log)

This transient prefix command binds several log suffix commands and infix arguments and displays them in a temporary buffer until a suffix is invoked. See Logging.

This is the same command that l is bound to in Magit buffers. If this command is invoked from a file-visiting buffer, then the initial value of the option (--) that limits the log to certain file(s) is set to the visited file.

C-c M-g l (magit-log-buffer-file)

This command shows the log for the file of blob that the current buffer visits. Renames are followed when a prefix argument is used or when --follow is an active log argument. When the region is active, the log is restricted to the selected line range.

User Option: magit-log-buffer-file-locked

This option controls whether magit-log-buffer-file uses a dedicated buffer. See Modes and Buffers.

C-c M-g t (magit-log-trace-definition)

This command shows the log for the definition at point.

C-c M-g M (magit-log-merged)

This command reads a commit and a branch in shows a log concerning the merge of the former into the latter. This shows multiple commits even in case of a fast-forward merge.

C-c M-g B (magit-blame)

This transient prefix command binds all blaming suffix commands along with the appropriate infix arguments and displays them in a temporary buffer until a suffix is invoked.

For more information about this and the following commands also see Blaming.

In addition to the magit-blame sub-transient, the dispatch transient also binds several blaming suffix commands directly. See Blaming for information about those commands and bindings.

C-c M-g p (magit-blob-previous)

This command visits the previous blob which modified the current file.

C-c M-g n (magit-blob-next)

This command visits the next blob which modified the current file.

C-c M-g v (magit-find-file)

This command reads a revision and file and visits the respective blob.

C-c M-g V (magit-blob-visit-file)

This command visits the file from the working tree, corresponding to the current blob. When visiting a blob or the version from the index, then it goes to the same location in the respective file in the working tree.

C-c M-g g (magit-status-here)

This command displays the status of the current repository in a buffer, like magit-status does. Additionally it tries to go to the position in that buffer, which corresponds to the position in the current file-visiting buffer (if any).

C-c M-g G (magit-display-repository-buffer)

This command reads and displays a Magit buffer belonging to the current repository, without refreshing it.

C-c M-g c (magit-commit)

This transient prefix command binds the following suffix commands along with the appropriate infix arguments and displays them in a temporary buffer until a suffix is invoked. See Initiating a Commit.

C-c M-g e (magit-edit-line-commit)

This command makes the commit editable that added the current line.

With a prefix argument it makes the commit editable that removes the line, if any. The commit is determined using git blame and made editable using git rebase --interactive if it is reachable from HEAD, or by checking out the commit (or a branch that points at it) otherwise.


Next: Minor Mode for Buffers Visiting Blobs, Previous: Wip Modes, Up: Miscellaneous   [Contents][Index]