Skip to content

Latest commit

 

History

History
263 lines (210 loc) · 11.1 KB

README.org

File metadata and controls

263 lines (210 loc) · 11.1 KB

Git contribution layer for Spacemacs

img/git.png

Table of Contents

Description

This layers adds extensive support for git.

Features:

New to Magit? Checkout the official intro.

Install

Layer

To use this contribution add it to your ~/.spacemacs

(setq-default dotspacemacs-configuration-layers '(git))

Recommended Settings

Read the documentation for the magit-push-always-verify variable, then you may wish to set it to nil in your dotspacemacs/user-config function.

(defun dotspacemacs/user-config ()
  (setq magit-push-always-verify nil))

The nag default is to prevent surprising behavior for newcomers, but causes the PP, Po, Pe (and more) push commands to nag you in the same way. Once you understand what they do, it is better simply to give the command you intend.

Magit status fullscreen

To display the magit status buffer in fullscreen set the variable git-magit-status-fullscreen to t in your dotspacemacs/user-init function.

(defun dotspacemacs/user-init ()
  (setq-default git-magit-status-fullscreen t)
)

Magit auto-complete

Magit auto-complete feature is enabled. For this feature to work best you have to setup your Git repository directory in your dotspacemacs/user-config function, this is the folder where you keep all your git-controlled projects (the path should end up with a ~=/~= to respect Emacs conventions):

(setq magit-repository-directories '("~/repos/"))

For more information, see Magit-User-Manual#Status-buffer

Magit SVN plugin

For convenience the magit SVN plugin can be activated directly in the Git layer by setting the variable git-enable-magit-svn-plugin to t.

(defun dotspacemacs/user-init ()
  (setq-default git-enable-magit-svn-plugin t)
)

Git

Of course if your OS does not ship with git (!) you’ll have to install it on your machine. You can download it from the download page.

Git-Flow

Git-flow is a standardized branching pattern for git repositories with the aim of making things more manageable. While there are tools to assist with making this easier, these do nothing you couldn’t do manually.

Support requires installation of the git-flow extensions. Please reference their installation page for assistance.

Working with Git

Git commands (start with g):

Key BindingDescription
SPC g bopen a magit blame
SPC g Ccommit changes
SPC g dshow diff against current head
SPC g h cclear highlights
SPC g h hhighlight regions by age of commits
SPC g h thighlight regions by last updated time
SPC g Iopen helm-gitignore
SPC g lopen a magit log
SPC g Ldisplay the log for a file
SPC g sopen a magit status window
SPC g mdisplay the last commit message of the current line
SPC g tlaunch the git time machine
  • Highlight by age of commit or last update time is provided by smeargle.
  • Git time machine is provided by git-timemachine.
  • Git last commit message per line is provided by git-messenger.

Magit

Spacemacs uses magit to manage Git repositories.

To open a status buffer, type in a buffer of a Git repository: SPC g s

hjkl navigation is enabled in all Magit buffers. The default Magit keys on hjkl (if they exist) are remapped on HJKL.

Here are the often used bindings inside a status buffer, please note that the following key bindings are valid in Vim editing style, in Emacs editing style you can refer directly to the magit manual:

Key BindingDescription
/evil-search
$open command output buffer
c copen a commit message buffer
b bcheckout a branch
b ccreate a branch
f ffetch changes
F -r Fpull and rebase
hgo left
jgo down
C-S-j or C-ngoto next magit section
kgo up
Kdiscard changes
C-S-k or C-pgoto previous magit section
lgo right
L lopen log buffer
nnext search occurrence
Nprevious search occurrence or SVN sub-menu
P Ppush
qquit
son a file or hunk in a diff: stage the file or hunk
+on a hunk: increase hunk size
-on a hunk: decrease hunk size
Sstage all
TABon a file: expand/collapse diff
uon a staged file: unstage
Uunstage all staged files
vgo to visual state
Vgo to visual-line state
C-vrevert item at point
z zstash changes

Commit message edition buffer

In a commit message buffer press C-c C-c to commit the changes with the entered message. Pressing C-c C-k will discard the commit message.

Key BindingDescription
hgo left
jgo down
kgo up
lgo right

Interactive rebase buffer

Key BindingDescription
cpick
eedit
ffixup
hgo left
jgo down
Jmove line down
kgo up
Kmove line up
C-kkill line
lgo right
rreword
ssquash
uundo
xexecute
yinsert

Quick guide for recurring use cases in Magit

  • Amend a commit:
    • L l to open log buffer
    • c a on the commit you want to amend
    • C-c C-c to submit the changes
  • Squash last commit:
    • L l to open log buffer
    • r e on the second to last commit, it opens the rebase buffer
    • j to put point on last commit
    • s to squash it
    • C-c C-c to continue to the commit message buffer
    • C-c C-c again when you have finished to edit the commit message
  • Force push a squashed commit:
    • in the status buffer you should see the new commit unpushed and the old commit unpulled
    • P -f P for force a push (beware usually it is not recommended to rewrite the history of a public repository, but if you are sure that you are the only one to work on a repository it is ok - i.e. in your fork).
  • Add upstream remote (the parent repository you have forked):
    • M to open the remote popup
    • a to add a remote, type the name (i.e. upstream) and the URL
  • Pull changes from upstream (the parent repository you have forked) and push:
    • F -r C-u F and choose upstream or the name you gave to it
    • P P to push the commit to origin

Git-Flow

magit-gitflow provides git-flow commands in its own magit menu.

Key BindingDescription
# fopen magit-gitflow menu

Git time machine

git-timemachine allows to quickly browse the commits of the current buffer.

Key BindingDescription
SPC g tstart git timemachine and initiate micro-state
cshow current commit
nshow next commit
Nshow previous commit
pshow previous commit
qleave micro-state and git timemachine
Ycopy current commit hash