2015-12-02 14:23:39 +00:00
#+TITLE : Version-Control layer
2015-06-10 16:44:30 +00:00
2019-05-02 21:49:30 +00:00
#+TAGS : layer|versioning
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description ][Description ]]
2017-08-28 21:58:10 +00:00
- [[#features ][Features: ]]
2017-05-22 14:16:12 +00:00
- [[#install ][Install ]]
- [[#layer ][Layer ]]
- [[#configuration ][Configuration ]]
2019-12-23 21:01:32 +00:00
- [[#differences-between-margin-packages ][Differences between margin packages ]]
2018-12-05 03:03:03 +00:00
- [[#key-bindings ][Key bindings ]]
2016-02-22 18:18:48 +00:00
- [[#vc-directory-buffer-commands ][VC Directory buffer commands ]]
- [[#commit-message-editing-buffer ][Commit message editing buffer ]]
diff-mode: define key bindings with leader key for vim editing style
This patch defines key bindings with leader key instead of evilified state to
make it easier for people those who edit in vim style to use diff-mode for both
of editing and reviewing files/buffers.
There are two use cases for diff-mode:
(1) to manually edit diff in a patch file
(2) to review diff that is generated by `vc-diff' or similar commands
The evilified state is useful for the case (2), but is confusing for the
case (1). Usually, users of vim editing style expect that they are in normal
state when a new buffer is created. However, when evilified state is used for
the case (1), some keys insert their character in a buffer, which let the users
think they are in insert state and keep hitting keys to edit the buffer, while
other keys invoke commands or change contents of buffer, which let them think
they are in normal state, so finally the user get lost what state they are in if
they don't know evilified state is used for diff-mode.
The changeset 58d521af5 "Unbreak diff-mode", originally written on Apr 2 2017,
tried to avoid the confusion by removing the evilified state configuration.
However, it is overwritten by the other and older changeset 8009e1bf5 "evilify
vc-* buffers", which is written on Feb 22 2016, for some reason.
This patch respects both of the use cases listed above, thus defines key
bindings with leader key instead of just removing the evilified state
configuration.
2018-06-19 14:41:18 +00:00
- [[#diff-mode ][Diff mode ]]
2016-02-22 18:18:48 +00:00
- [[#log-view-buffer ][Log view buffer ]]
- [[#annotation-buffer ][Annotation buffer ]]
2017-05-22 14:16:12 +00:00
- [[#version-control-transient-state ][Version Control Transient-state ]]
- [[#smerge-mode-transient-state ][Smerge Mode Transient-state ]]
2016-02-22 18:18:48 +00:00
- [[#toggles ][Toggles ]]
2015-06-10 16:44:30 +00:00
* Description
This layers adds general configuration for [[http://www.gnu.org/software/emacs/manual/html_node/emacs/Version-Control.html ][Emacs VC ]].
It should work with all VC backends such as Git, Mercurial, Bazaar, SVN, etc...
2017-08-28 21:58:10 +00:00
** Features:
- highlights uncommitted changes in the fringe or margin with [[https://github.com/dgutov/diff-hl ][diff-hl ]], [[https://github.com/syohex/emacs-git-gutter ][git-gutter ]], or [[https://github.com/nonsequitur/git-gutter-plus ][git-gutter+ ]]
- adds vcs transient-state ~SPC g.~ to allow quick navigation and modification of buffer hunks.
2015-11-15 19:01:58 +00:00
2015-06-10 16:44:30 +00:00
* Install
** Layer
2016-01-06 05:21:55 +00:00
To use this configuration layer, add it to your =~/.spacemacs= . You will need to
add =version-control= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
2015-11-15 19:01:58 +00:00
* Configuration
2019-12-23 21:01:32 +00:00
You can choose the package to facilitate the diff transient-state and show
margins by setting the =version-control-diff-tool= variable to one of the
supported packages:
- [[https://github.com/dgutov/diff-hl ][diff-hl ]]
- [[https://github.com/syohex/emacs-git-gutter ][git-gutter ]]
- [[https://github.com/nonsequitur/git-gutter-plus ][git-gutter+ ]] (default)
2015-11-15 19:01:58 +00:00
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
'(version-control :variables
version-control-diff-tool 'diff-hl)
2015-11-15 19:01:58 +00:00
#+END_SRC
2019-05-26 20:58:52 +00:00
You can choose the side on which the diff appears (by default it's the right side)
2016-11-01 09:27:45 +00:00
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
'(version-control :variables
version-control-diff-side 'left)
2016-11-01 09:27:45 +00:00
#+END_SRC
2015-11-30 04:00:57 +00:00
To automatically enable diff margins in all buffers, set
=version-control-global-margin=
2015-11-15 19:01:58 +00:00
#+BEGIN_SRC emacs-lisp
2018-09-19 03:54:47 +00:00
'(version-control :variables
version-control-global-margin t)
2015-11-15 19:01:58 +00:00
#+END_SRC
2019-12-23 21:01:32 +00:00
** Differences between margin packages
2015-11-30 04:00:57 +00:00
This layer contains generalized mappings for three diff margin packages:
2019-12-23 21:01:32 +00:00
=diff-hl= , =git-gutter= , and =git-gutter+= .
2015-11-15 19:01:58 +00:00
2015-11-30 04:00:57 +00:00
There are some differences between packages that might have some people prefer
one over the other:
2015-11-15 19:01:58 +00:00
| Feature | diff-hl | git-gutter | git-gutter+ |
|-------------------------------------+---------+------------+-------------|
| Show in fringe | X | X | X |
| Extended VCS support (e.g. hg, svn) | X | X | |
| Stage hunks from buffer | | X | X |
| Dired support | X | | |
2018-12-05 03:03:03 +00:00
* Key bindings
2016-02-22 18:18:48 +00:00
VC commands:
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2016-02-22 18:18:48 +00:00
|-------------+--------------------------------------------------------|
2019-04-21 08:33:59 +00:00
| ~SPC g .~ | Version control transient-state |
2020-07-17 20:14:59 +00:00
| ~SPC g o~ | Browser at remote |
2019-04-21 08:33:59 +00:00
| ~SPC g r~ | Smerge mode transient-state |
| ~SPC g v =~ | Open a hunk under the point in the diff buffer |
| ~SPC g v D~ | Compare the entire working tree with head |
| ~SPC g v e~ | Show diff against current head using ediff |
| ~SPC g v g~ | Visually annotate the current file |
| ~SPC g v d~ | Open the VC Directory buffer |
| ~SPC g v +~ | Update the working copy |
| ~SPC g v i~ | Register (add) into a version control system |
| ~SPC g v u~ | Revert working copy to their repository contents |
| ~SPC g v l~ | List the change log |
| ~SPC g v L~ | List the change log for the current VC controlled tree |
| ~SPC g v v~ | Do the next logical VC operation (=vc-next-action=) |
| ~SPC g v I~ | Ignore file (=vc-ignore=) |
| ~SPC g v r~ | Resolve conflicts in file |
2016-02-22 18:18:48 +00:00
** VC Directory buffer commands
You can hit ~SPC pv~ from the current project to open the VC Directory buffer,
or use ~SPC g v d~ for specifying a root directory.
Then you may mark (=m= key) files you are interested in, to form a fileset.
Most commands described above are applicable to filesets too.
To some of them are given shortcuts:
2019-04-21 08:33:59 +00:00
| Key binding | Description |
|-------------+-----------------------------------|
| ~=~ | Compare selected files with head |
| ~c~ | Open a =commit message buffer= |
| ~l~ | List changes |
| ~a~ | Annotate selected files |
| ~i~ | Add into a version control system |
| ~r~ | Refresh directory view |
| ~E~ | Ignore file under cursor |
2016-02-22 18:18:48 +00:00
Navigation and interaction commands in the VC Directory buffer:
2019-04-21 08:33:59 +00:00
| Key binding | Description |
2016-02-22 18:18:48 +00:00
|-----------------+--------------------|
2019-04-21 08:33:59 +00:00
| ~j~ or ~M-n~ | Next file |
| ~k~ or ~M-p~ | Previous file |
| ~gj~ or ~TAB~ | Next directory |
| ~gk~ or ~S-TAB~ | Previous directory |
| ~m~ | Mark a file |
| ~u~ | Unmark a file |
2016-02-22 18:18:48 +00:00
** Commit message editing 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 and close this buffer.
diff-mode: define key bindings with leader key for vim editing style
This patch defines key bindings with leader key instead of evilified state to
make it easier for people those who edit in vim style to use diff-mode for both
of editing and reviewing files/buffers.
There are two use cases for diff-mode:
(1) to manually edit diff in a patch file
(2) to review diff that is generated by `vc-diff' or similar commands
The evilified state is useful for the case (2), but is confusing for the
case (1). Usually, users of vim editing style expect that they are in normal
state when a new buffer is created. However, when evilified state is used for
the case (1), some keys insert their character in a buffer, which let the users
think they are in insert state and keep hitting keys to edit the buffer, while
other keys invoke commands or change contents of buffer, which let them think
they are in normal state, so finally the user get lost what state they are in if
they don't know evilified state is used for diff-mode.
The changeset 58d521af5 "Unbreak diff-mode", originally written on Apr 2 2017,
tried to avoid the confusion by removing the evilified state configuration.
However, it is overwritten by the other and older changeset 8009e1bf5 "evilify
vc-* buffers", which is written on Feb 22 2016, for some reason.
This patch respects both of the use cases listed above, thus defines key
bindings with leader key instead of just removing the evilified state
configuration.
2018-06-19 14:41:18 +00:00
** Diff mode
2019-04-21 08:33:59 +00:00
| Key binding | Description |
|-------------+------------------------------------------------|
| ~SPC m a~ | Apply a hunk |
| ~SPC m d~ | Kill the hunk at point |
2019-05-26 20:58:52 +00:00
| ~SPC m D~ | Kill the current file's hunk |
2019-04-21 08:33:59 +00:00
| ~SPC m e~ | Call =ediff-patch-file= on current buffer |
| ~SPC m f c~ | Convert unified diffs to context diffs |
| ~SPC m f r~ | Reverse the direction of the diffs |
| ~SPC m f u~ | Convert context diffs to unified diffs |
| ~SPC m g~ | Jump to the corresponding source line |
| ~SPC m j~ | Next hunk |
| ~SPC m J~ | Next file |
| ~SPC m k~ | Previous hunk |
| ~SPC m K~ | Previous file |
| ~SPC m q~ | Close the diff window |
| ~SPC m r~ | Revert a hunk |
| ~SPC m s~ | Split the current hunk at point into two hunks |
| ~SPC m u~ | Undo |
diff-mode: define key bindings with leader key for vim editing style
This patch defines key bindings with leader key instead of evilified state to
make it easier for people those who edit in vim style to use diff-mode for both
of editing and reviewing files/buffers.
There are two use cases for diff-mode:
(1) to manually edit diff in a patch file
(2) to review diff that is generated by `vc-diff' or similar commands
The evilified state is useful for the case (2), but is confusing for the
case (1). Usually, users of vim editing style expect that they are in normal
state when a new buffer is created. However, when evilified state is used for
the case (1), some keys insert their character in a buffer, which let the users
think they are in insert state and keep hitting keys to edit the buffer, while
other keys invoke commands or change contents of buffer, which let them think
they are in normal state, so finally the user get lost what state they are in if
they don't know evilified state is used for diff-mode.
The changeset 58d521af5 "Unbreak diff-mode", originally written on Apr 2 2017,
tried to avoid the confusion by removing the evilified state configuration.
However, it is overwritten by the other and older changeset 8009e1bf5 "evilify
vc-* buffers", which is written on Feb 22 2016, for some reason.
This patch respects both of the use cases listed above, thus defines key
bindings with leader key instead of just removing the evilified state
configuration.
2018-06-19 14:41:18 +00:00
A transient buffer is also defined, start it with ~SPC m .~ or ~, .~
2019-04-21 08:33:59 +00:00
| Key binding | Description |
|-------------+---------------|
| ~j~ | Next hunk |
| ~J~ | Next file |
| ~k~ | Previous hunk |
| ~K~ | Previous file |
2016-02-22 18:18:48 +00:00
** Log view buffer
2019-04-21 08:33:59 +00:00
| Key binding | Description |
2016-02-22 18:18:48 +00:00
|------------------------+----------------------------------------------------------------------------|
2019-04-21 08:33:59 +00:00
| ~C-j~ or ~M-n~ | Next message |
| ~C-k~ or ~M-p~ | Previous message |
| ~gj~ or ~J~ or ~TAB~ | Next file |
| ~gk~ or ~K~ or ~S-TAB~ | Previous file |
| ~f~ or ~ENTER~ | Visit the version at point |
| ~d~ | Display a diff between the revision at point and the next earlier revision |
| ~o~ | Use for jumping to links |
| ~H~ | Toggle hiding of the full message |
2016-02-22 18:18:48 +00:00
** Annotation buffer
2019-04-21 08:33:59 +00:00
| Key binding | Description |
|-------------+--------------------------------------------------------------------------------|
| ~J~ | Visit the annotation of the revision after this one |
| ~K~ | Visit the annotation of the revision previous to this one |
| ~L~ | visit the log of the revision at line |
| ~H~ | Toggle whether or not the annotation is visible |
| ~a~ | Visit the annotation of the revision identified in the current line |
| ~p~ | Visit the annotation of the revision before the revision at line |
2019-05-26 20:58:52 +00:00
| ~d~ | Display the diff between the current line's revision and the previous revision |
2019-04-21 08:33:59 +00:00
| ~f~ | Show in a buffer the file revision indicated by the current line |
2015-11-15 19:01:58 +00:00
2016-01-30 11:32:53 +00:00
** Version Control Transient-state
2018-11-12 22:12:39 +00:00
Use ~SPC g .~ to enter a transient state for quickly navigating between hunks in a buffer. During that state, the following bindings are active:
2015-11-15 19:01:58 +00:00
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2015-11-15 19:01:58 +00:00
|-------------+------------------------------|
2018-10-22 08:09:55 +00:00
| ~h~ | Show diff of hunk |
| ~n~ | Next hunk |
| ~N~ or ~p~ | Previous hunk |
| ~r~ | Revert hunk |
| ~s~ | Stage hunk |
| ~t~ | Toggle margin indicators |
| ~w~ | Stage file |
| ~u~ | Unstage file |
| ~d~ | Repo diff popup |
| ~D~ | Show diffs of unstaged hunks |
| ~c~ | Commit with popup |
| ~C~ | Commit |
| ~P~ | Push repo with popup |
| ~f~ | Fetch for repo with popup |
| ~F~ | Pull repo with popup |
| ~l~ | Show repo log |
| ~z~ | Recenter buffer in window |
2017-03-12 13:22:03 +00:00
** Smerge Mode Transient-state
2019-04-21 08:33:59 +00:00
Movement:
| Key binding | Description |
|----------------------------+---------------------|
| ~SPC g r n~ | Next hunk |
| ~SPC g r N~ or ~SPC g r p~ | Previous hunk |
| ~SPC g r j~ | Go to next line |
| ~SPC g r k~ | Go to previous line |
Merge Actions:
| Key binding | Description |
|-------------+--------------|
| ~SPC g r b~ | Keep base |
| ~SPC g r m~ | Keep mine |
| ~SPC g r a~ | Keep all |
| ~SPC g r o~ | Keep other |
| ~SPC g r c~ | Keep current |
| ~SPC g r K~ | Kill current |
Diff:
| Key binding | Description |
|-------------+---------------------|
| ~SPC g r <~ | Diff base and mine |
| ~SPC g r =~ | Diff mine and other |
| ~SPC g r >~ | Diff base and other |
| ~SPC g r r~ | Refine |
| ~SPC g r e~ | Ediff |
Other:
| Key binding | Description |
|-------------+--------------------------------|
| ~SPC g r C~ | Combine current and next hunks |
| ~SPC g r u~ | Undo |
| ~SPC g r q~ | Quit transient state |
2016-02-22 18:18:48 +00:00
** Toggles
2018-01-27 14:08:07 +00:00
2018-12-05 03:03:03 +00:00
| Key binding | Description |
2016-02-22 18:18:48 +00:00
|-------------+------------------------------|
2019-04-21 08:33:59 +00:00
| ~SPC T d~ | Toggle diff margins |
| ~SPC T C-d~ | Toggle diff margins globally |