2015-06-10 16:44:30 +00:00
|
|
|
#+TITLE: Git contribution layer for Spacemacs
|
2015-11-08 18:04:44 +00:00
|
|
|
#+HTML_HEAD_EXTRA: <link rel="stylesheet" type="text/css" href="../../../css/readtheorg.css" />
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-11-15 19:01:58 +00:00
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
[[file:img/git.png]]
|
|
|
|
|
2015-10-30 11:20:58 +00:00
|
|
|
* Table of Contents :TOC_4_org:noexport:
|
|
|
|
- [[Description][Description]]
|
|
|
|
- [[Features:][Features:]]
|
|
|
|
- [[Install][Install]]
|
|
|
|
- [[Layer][Layer]]
|
|
|
|
- [[Magit status fullscreen][Magit status fullscreen]]
|
|
|
|
- [[Magit auto-complete][Magit auto-complete]]
|
|
|
|
- [[Magit SVN plugin][Magit SVN plugin]]
|
2015-12-21 12:56:38 +00:00
|
|
|
- [[Global git commit mode][Global git commit mode]]
|
2015-10-30 11:20:58 +00:00
|
|
|
- [[Git][Git]]
|
|
|
|
- [[Git-Flow][Git-Flow]]
|
2015-12-20 06:02:12 +00:00
|
|
|
- [[Org integration][Org integration]]
|
2015-10-30 11:20:58 +00:00
|
|
|
- [[Working with Git][Working with Git]]
|
|
|
|
- [[Magit][Magit]]
|
|
|
|
- [[Staging lines][Staging lines]]
|
|
|
|
- [[Commit message editing buffer][Commit message editing buffer]]
|
|
|
|
- [[Interactive rebase buffer][Interactive rebase buffer]]
|
|
|
|
- [[Quick guide for recurring use cases in Magit][Quick guide for recurring use cases in Magit]]
|
|
|
|
- [[Git-Flow][Git-Flow]]
|
|
|
|
- [[Git time machine][Git time machine]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
* Description
|
|
|
|
This layers adds extensive support for [[http://git-scm.com/][git]].
|
|
|
|
|
2015-06-10 21:16:01 +00:00
|
|
|
** Features:
|
2015-12-11 12:01:52 +00:00
|
|
|
- git repository management the indispensable [[http://magit.vc/][magit]] package
|
2015-06-10 16:44:30 +00:00
|
|
|
- [[https://github.com/jtatarik/magit-gitflow][git-flow]] add-on for magit.
|
|
|
|
- quick in buffer history browsing with [[https://github.com/pidu/git-timemachine][git-timemachine]].
|
|
|
|
- quick in buffer last commit message per line with [[https://github.com/syohex/emacs-git-messenger][git-messenger]]
|
|
|
|
- colorize buffer line by age of commit with [[https://github.com/syohex/emacs-smeargle][smeargle]]
|
|
|
|
- gitignore generator with [[https://github.com/jupl/helm-gitignore][helm-gitignore]]
|
2015-12-20 06:02:12 +00:00
|
|
|
- org integration with magit via [[https://github.com/magit/orgit][orgit]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-07-29 18:15:01 +00:00
|
|
|
New to Magit? Checkout the [[http://magit.vc/about.html][official intro]].
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
* Install
|
|
|
|
** Layer
|
|
|
|
To use this contribution add it to your =~/.spacemacs=
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(setq-default dotspacemacs-configuration-layers '(git))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Magit status fullscreen
|
|
|
|
To display the =magit status= buffer in fullscreen set the variable
|
2015-09-28 06:05:18 +00:00
|
|
|
=git-magit-status-fullscreen= to =t= in your =dotspacemacs/user-init= function.
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2015-09-28 06:05:18 +00:00
|
|
|
(defun dotspacemacs/user-init ()
|
2015-06-10 16:44:30 +00:00
|
|
|
(setq-default git-magit-status-fullscreen t)
|
|
|
|
)
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
** Magit auto-complete
|
|
|
|
Magit auto-complete feature is enabled. For this feature to work best you
|
2015-09-28 06:05:18 +00:00
|
|
|
have to setup your Git repository directory in your =dotspacemacs/user-config=
|
2015-06-10 16:44:30 +00:00
|
|
|
function, this is the folder where you keep all your git-controlled projects
|
2015-10-01 15:23:33 +00:00
|
|
|
(the path should end up with a ~/~ to respect Emacs conventions):
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2015-07-02 12:36:26 +00:00
|
|
|
(setq magit-repository-directories '("~/repos/"))
|
2015-06-10 16:44:30 +00:00
|
|
|
#+END_SRC
|
|
|
|
|
2015-08-07 18:55:57 +00:00
|
|
|
For more information, see [[http://magit.vc/manual/magit.html#Status-buffer][Magit-User-Manual#Status-buffer]]
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
** 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=.
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2015-09-28 06:05:18 +00:00
|
|
|
(defun dotspacemacs/user-init ()
|
2015-06-10 16:44:30 +00:00
|
|
|
(setq-default git-enable-magit-svn-plugin t)
|
|
|
|
)
|
|
|
|
#+END_SRC
|
|
|
|
|
2015-12-21 12:56:38 +00:00
|
|
|
** Global git commit mode
|
|
|
|
Spacemacs can be used as the =$EDITOR= (or =$GIT_EDITOR=) for editing git
|
|
|
|
commits messages. To enable this you have to add the following line to your
|
|
|
|
=dotspacemacs/user-config=:
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp
|
|
|
|
(global-git-commit-mode t)
|
|
|
|
#+end_src
|
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
** Git
|
|
|
|
Of course if your OS does not ship with git (!) you'll have to install it
|
2015-06-10 21:16:01 +00:00
|
|
|
on your machine. You can download it from the [[http://git-scm.com/downloads][download page]].
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-08-07 02:02:00 +00:00
|
|
|
** 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
|
|
|
|
[[https://github.com/petervanderdoes/gitflow/wiki][installation page]] for assistance.
|
2015-09-06 06:49:28 +00:00
|
|
|
|
2015-12-20 06:02:12 +00:00
|
|
|
** Org integration
|
|
|
|
|
|
|
|
See the commentary section of the package [[https://github.com/magit/orgit/blob/master/orgit.el#L28][here]].
|
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
* Working with Git
|
2015-06-16 02:11:11 +00:00
|
|
|
Git commands (start with ~g~):
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|-------------+-----------------------------------------------------|
|
|
|
|
| ~SPC g b~ | open a =magit= blame |
|
2015-10-14 19:29:24 +00:00
|
|
|
| ~SPC g B~ | quit =magit= blame |
|
2015-11-02 05:16:13 +00:00
|
|
|
| ~SPC g c~ | commit changes |
|
|
|
|
| ~SPC g C~ | checkout branches |
|
2015-11-15 19:01:58 +00:00
|
|
|
| ~SPC g d~ | show diff prompt |
|
|
|
|
| ~SPC g D~ | show diff against current head |
|
|
|
|
| ~SPC g e~ | show ediff comparison |
|
|
|
|
| ~SPC g E~ | show ediff against current head |
|
|
|
|
| ~SPC g f~ | show fetch prompt |
|
|
|
|
| ~SPC g F~ | show pull prompt |
|
2015-11-02 05:16:13 +00:00
|
|
|
| ~SPC g H c~ | clear highlights |
|
|
|
|
| ~SPC g H h~ | highlight regions by age of commits |
|
|
|
|
| ~SPC g H t~ | highlight regions by last updated time |
|
2015-10-23 01:43:05 +00:00
|
|
|
| ~SPC g i~ | git init a given directory |
|
2015-06-10 16:44:30 +00:00
|
|
|
| ~SPC g I~ | open =helm-gitignore= |
|
|
|
|
| ~SPC g l~ | open a =magit= log |
|
2015-06-21 07:50:00 +00:00
|
|
|
| ~SPC g L~ | display the log for a file |
|
2015-11-15 19:01:58 +00:00
|
|
|
| ~SPC g P~ | show push prompt |
|
2015-06-10 16:44:30 +00:00
|
|
|
| ~SPC g s~ | open a =magit= status window |
|
2015-12-01 06:43:29 +00:00
|
|
|
| ~SPC g S~ | stage current file |
|
2015-06-10 16:44:30 +00:00
|
|
|
| ~SPC g m~ | display the last commit message of the current line |
|
|
|
|
| ~SPC g t~ | launch the git time machine |
|
2015-12-01 06:43:29 +00:00
|
|
|
| ~SPC g U~ | unstage current file |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
- Highlight by age of commit or last update time is provided by
|
|
|
|
[[https://github.com/syohex/emacs-smeargle][smeargle]].
|
|
|
|
- Git time machine is provided by [[https://github.com/pidu/git-timemachine][git-timemachine]].
|
|
|
|
- Git last commit message per line is provided by [[https://github.com/syohex/emacs-git-messenger][git-messenger]].
|
|
|
|
|
|
|
|
** Magit
|
2015-10-12 23:12:09 +00:00
|
|
|
Spacemacs uses [[http://magit.vc/][magit]] to manage Git repositories.
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-06-12 01:23:07 +00:00
|
|
|
To open a =status buffer=, type in a buffer of a Git repository: ~SPC g s~
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-10-29 16:21:17 +00:00
|
|
|
Spacemacs uses [[https://github.com/justbur/evil-magit][evil-magit]] for key bindings in magit buffers (unless your editing
|
|
|
|
style is set to emacs, in which case you get the default magit bindings), which
|
|
|
|
are the standard magit key bindings with some minimal changes to make them
|
|
|
|
comfortable for evil users.
|
2015-10-29 16:16:40 +00:00
|
|
|
|
|
|
|
Here are the often used bindings inside a =status buffer=:
|
|
|
|
|
2016-01-03 14:58:32 +00:00
|
|
|
| Key Binding | Description |
|
|
|
|
|-------------+---------------------------------------------------------------------|
|
|
|
|
| ~/~ | evil-search |
|
|
|
|
| ~$~ | open =command output buffer= |
|
|
|
|
| ~c c~ | open a =commit message buffer= |
|
|
|
|
| ~b b~ | checkout a branch |
|
|
|
|
| ~b c~ | create a branch |
|
|
|
|
| ~f f~ | fetch changes |
|
|
|
|
| ~F (r) u~ | pull tracked branch and rebase |
|
|
|
|
| ~gr~ | refresh |
|
|
|
|
| ~j~ | goto next magit section |
|
|
|
|
| ~C-j~ | next visual line |
|
|
|
|
| ~k~ | goto previous magit section |
|
|
|
|
| ~C-k~ | previous visual line |
|
|
|
|
| ~l l~ | open =log buffer= |
|
|
|
|
| ~n~ | next search occurrence |
|
|
|
|
| ~N~ | previous search occurrence |
|
|
|
|
| ~o~ | revert item at point |
|
|
|
|
| ~P u~ | push to tracked branch |
|
|
|
|
| ~P m~ | push to matching branch (e.g., upstream/develop to origin/develop) |
|
|
|
|
| ~q~ | quit |
|
|
|
|
| ~s~ | on a file or hunk in a diff: stage the file or hunk |
|
|
|
|
| ~x~ | discard changes |
|
|
|
|
| ~+~ | on a hunk: increase hunk size |
|
|
|
|
| ~-~ | on a hunk: decrease hunk size |
|
|
|
|
| ~S~ | stage all |
|
|
|
|
| ~TAB~ | on a file: expand/collapse diff |
|
|
|
|
| ~u~ | on a staged file: unstage |
|
|
|
|
| ~U~ | unstage all staged files |
|
|
|
|
| ~v or V~ | select multiple lines |
|
|
|
|
| ~z z~ | stash changes |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-09-30 09:43:42 +00:00
|
|
|
** Staging lines
|
|
|
|
Magit allows you to stage specific lines by selecting them in a diff and hitting
|
|
|
|
=s= to stage. Due to inconsistencies between Vim and Emacs editing styles, if
|
|
|
|
you enter visual line state with =V=, you will stage one more line than
|
|
|
|
intended. To work around this, you can use =v= instead (since Magit only stages
|
|
|
|
whole lines, in any case).
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-10-29 16:16:40 +00:00
|
|
|
** Commit message editing buffer
|
|
|
|
In a commit message buffer press ~,c~ (if =dotspacemacs-major-mode-leader-key= is ~,~)
|
|
|
|
or ~C-c C-c~ to commit the changes with the entered message. Pressing ~,a~ or ~C-c C-k~
|
|
|
|
will discard the commit message.
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|-------------+-------------|
|
|
|
|
| ~h~ | go left |
|
|
|
|
| ~j~ | go down |
|
|
|
|
| ~k~ | go up |
|
|
|
|
| ~l~ | go right |
|
|
|
|
|
|
|
|
** Interactive rebase buffer
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|-------------+----------------|
|
2015-10-30 11:20:58 +00:00
|
|
|
| ~c~ or ~p~ | pick |
|
|
|
|
| ~e~ | edit |
|
|
|
|
| ~f~ | fixup |
|
|
|
|
| ~j~ | go down |
|
|
|
|
| ~gj~ | move line down |
|
|
|
|
| ~k~ | go up |
|
|
|
|
| ~gk~ | move line up |
|
|
|
|
| ~d~ or ~x~ | kill line |
|
|
|
|
| ~r~ | reword |
|
|
|
|
| ~s~ | squash |
|
|
|
|
| ~u~ | undo |
|
|
|
|
| ~y~ | insert |
|
|
|
|
| ~!~ | execute |
|
2015-06-10 16:44:30 +00:00
|
|
|
|
|
|
|
** Quick guide for recurring use cases in Magit
|
|
|
|
|
|
|
|
- Amend a commit:
|
2015-10-29 16:16:40 +00:00
|
|
|
- ~l l~ to open =log buffer=
|
2015-06-12 01:23:07 +00:00
|
|
|
- ~c a~ on the commit you want to amend
|
2015-10-29 16:16:40 +00:00
|
|
|
- ~,c~ or ~C-c C-c~ to submit the changes
|
2015-06-10 16:44:30 +00:00
|
|
|
- Squash last commit:
|
2015-10-29 16:16:40 +00:00
|
|
|
- ~l l~ to open =log buffer=
|
2015-07-02 17:56:02 +00:00
|
|
|
- ~r e~ on the second to last commit, it opens the =rebase buffer=
|
2015-06-12 01:23:07 +00:00
|
|
|
- ~j~ to put point on last commit
|
|
|
|
- ~s~ to squash it
|
2015-10-29 16:16:40 +00:00
|
|
|
- ~,c~ or ~C-c C-c~ to continue to the =commit message buffer=
|
|
|
|
- ~,c~ or ~C-c C-c~ again when you have finished to edit the commit message
|
2015-06-10 16:44:30 +00:00
|
|
|
- Force push a squashed commit:
|
2015-06-10 21:16:01 +00:00
|
|
|
- in the =status buffer= you should see the new commit unpushed and the old
|
|
|
|
commit unpulled
|
2015-06-12 01:23:07 +00:00
|
|
|
- ~P -f P~ for force a push (*beware* usually it is not recommended to rewrite
|
2015-06-10 21:16:01 +00:00
|
|
|
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).
|
2015-06-10 16:44:30 +00:00
|
|
|
- Add upstream remote (the parent repository you have forked):
|
2015-07-02 04:36:26 +00:00
|
|
|
- ~M~ to open the =remote popup=
|
2015-06-12 01:23:07 +00:00
|
|
|
- ~a~ to add a remote, type the name (i.e. =upstream=) and the URL
|
2015-06-10 16:44:30 +00:00
|
|
|
- Pull changes from upstream (the parent repository you have forked) and push:
|
2015-07-03 02:08:03 +00:00
|
|
|
- ~F -r C-u F~ and choose =upstream= or the name you gave to it
|
2015-06-12 01:23:07 +00:00
|
|
|
- ~P P~ to push the commit to =origin=
|
2015-06-10 16:44:30 +00:00
|
|
|
|
2015-08-07 02:02:00 +00:00
|
|
|
** Git-Flow
|
|
|
|
|
|
|
|
[[https://github.com/jtatarik/magit-gitflow][magit-gitflow]] provides git-flow commands in its own magit menu.
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|-------------+-------------------------|
|
2015-10-24 03:29:58 +00:00
|
|
|
| ~%~ | open magit-gitflow menu |
|
2015-08-07 02:02:00 +00:00
|
|
|
|
2015-06-10 16:44:30 +00:00
|
|
|
** Git time machine
|
|
|
|
|
|
|
|
[[https://github.com/pidu/git-timemachine][git-timemachine]] allows to quickly browse the commits of the current buffer.
|
|
|
|
|
|
|
|
| Key Binding | Description |
|
|
|
|
|-------------+------------------------------------------------|
|
|
|
|
| ~SPC g t~ | start git timemachine and initiate micro-state |
|
|
|
|
| ~c~ | show current commit |
|
|
|
|
| ~n~ | show next commit |
|
|
|
|
| ~N~ | show previous commit |
|
|
|
|
| ~p~ | show previous commit |
|
|
|
|
| ~q~ | leave micro-state and git timemachine |
|
|
|
|
| ~Y~ | copy current commit hash |
|
2015-07-02 04:36:26 +00:00
|
|
|
|
|
|
|
# LocalWords: unpulled
|