Difference between revisions of "Git"

From WikEmacs
Jump to navigation Jump to search
(git auto commit mode)
(→‎Highlight diffs: git hunks)
(10 intermediate revisions by 2 users not shown)
Line 24: Line 24:
  
 
== Highlight uncommited changes ==
 
== Highlight uncommited changes ==
 +
 +
=== Git gutter ===
  
 
[https://github.com/syohex/emacs-git-gutter Git-gutter]  is an extension to highlight uncommitted changes on the left side of the window, indicating wether a line has been inserted, modified or deleted, and allowing you to jump between and revert them selectively. [https://github.com/dgutov/diff-hl diff-hl] does it too and works with Git, Mercurial, Bazaar and Svn, and it provides similar functionnality for '''dired'''. Both are available in [[ELPA]]. They are [[Tramp]]-aware.
 
[https://github.com/syohex/emacs-git-gutter Git-gutter]  is an extension to highlight uncommitted changes on the left side of the window, indicating wether a line has been inserted, modified or deleted, and allowing you to jump between and revert them selectively. [https://github.com/dgutov/diff-hl diff-hl] does it too and works with Git, Mercurial, Bazaar and Svn, and it provides similar functionnality for '''dired'''. Both are available in [[ELPA]]. They are [[Tramp]]-aware.
Line 31: Line 33:
 
     (add-hook 'python-mode-hook 'git-gutter-mode)
 
     (add-hook 'python-mode-hook 'git-gutter-mode)
  
=== Jump between changes ===
+
==== Jump between changes ====
  
 
To jump between changes: {{Command|git-gutter:next-hunk}} or {{Command|diff-hl-next-hunk}}.
 
To jump between changes: {{Command|git-gutter:next-hunk}} or {{Command|diff-hl-next-hunk}}.
 +
 +
[[File:git-gutter.png]]
 +
 +
=== Highlight diffs ===
 +
 +
[https://github.com/dgutov/diff-hl Diff-hl] goes a little further than git-gutter in that it can highlight the uncommited diffs, even from [[Dired]]. And we can get them on the fly while we type:
 +
 +
    (diff-hl-flydiff-mode)
 +
 +
=== Browse and stage hunks with Helm ===
 +
 +
[https://github.com/torgeir/helm-hunks.el Helm-hunks] allows to jump around git hunks with helm, to preview them on the fly, and to stage them.
  
 
== Commit on every change ==
 
== Commit on every change ==
  
[git-auto-commit-mode | http://melpa.org/#/git-auto-commit-mode] (on MELPA) is a minor mode that tries to commit a change to a file after every save. It can also push automatically.
+
[http://melpa.org/#/git-auto-commit-mode git-auto-commit-mode] (on MELPA) is a minor mode that tries to commit a change to a file after every save. It can also push automatically.
 +
 
 +
== See previous versions of file ==
 +
 
 +
It's very easy with [https://github.com/pidu/git-timemachine git-timemachine]. Once you have called {{Command|git-timemachine}} you'll have the keys:
 +
 
 +
* '''p''' Visit previous historic version
 +
* '''n''' Visit next historic version
 +
* '''w''' Copy the abbreviated hash of the current historic version
 +
* '''W''' Copy the full hash of the current historic version
 +
* '''g''' Goto nth revision
 +
* '''q''' Exit the time machine.
 +
 
 +
== Choose an issue against the current list in a commit buffer ==
 +
 
 +
With github, gitlab and others, it is possible to refer to a particular issue in a commit. So, in Emacs, it would be handy to pick our issue in the list of open issues, instead of remembering its id. This is possible with the [https://gitlab.com/emacs-stuff/git-commit-insert-issue git-commit-insert-issue] package (only github at the moment), which will automatically fire an helm interface when it detects than we wrote something like "fixes #".
  
= Interfaces to github =
+
= See also =
  
== Clone a github repo ==
+
See also the full list of packages to interact with Github, Gitlab and others in the [[Github]] page.
  
[https://github.com/dgtized/github-clone.el Github-clone] (in MELPA) is a project to clone a github repository. The command {{Command | github-clone}} will prompt for a repository and directory to clone to. In one shot, it will use the github api to fork the repo if you are not the owner, clone the repo to the specified directory, and add a remote called upstream if the repository is a fork.
+
See a full list and a method to install them all at once on [https://github.com/tarsius/git-elisp tarsiu's github page].
  
 
[[Category:Version Control]][[Category:Convenience]][[Category:Third Party Package]]
 
[[Category:Version Control]][[Category:Convenience]][[Category:Third Party Package]]

Revision as of 19:56, 19 July 2016

Packages to interfere with the git version control system.


Full interfaces

Magit

Magit is a great Emacs mode for working with Git repositories. It provides a convenient interface for the most common Git operations. Please visit its own Magit page.

Specific use cases

Git blame

Git-blame is a package, available in ELPA, which provides a minor mode for incremental blame.

Show last commit message for current line

This package provides a function called git-messenger:popup-message that when called will pop-up the last git commit message for the current line. This uses the git-blame tool internally.

Available in ELPA.


Highlight uncommited changes

Git gutter

Git-gutter is an extension to highlight uncommitted changes on the left side of the window, indicating wether a line has been inserted, modified or deleted, and allowing you to jump between and revert them selectively. diff-hl does it too and works with Git, Mercurial, Bazaar and Svn, and it provides similar functionnality for dired. Both are available in ELPA. They are Tramp-aware.

After installation, call the minor modes or enable them:

   (add-hook 'python-mode-hook 'git-gutter-mode)

Jump between changes

To jump between changes: M-x git-gutter:next-hunk or M-x diff-hl-next-hunk.

Git-gutter.png

Highlight diffs

Diff-hl goes a little further than git-gutter in that it can highlight the uncommited diffs, even from Dired. And we can get them on the fly while we type:

   (diff-hl-flydiff-mode)

Browse and stage hunks with Helm

Helm-hunks allows to jump around git hunks with helm, to preview them on the fly, and to stage them.

Commit on every change

git-auto-commit-mode (on MELPA) is a minor mode that tries to commit a change to a file after every save. It can also push automatically.

See previous versions of file

It's very easy with git-timemachine. Once you have called M-x git-timemachine you'll have the keys:

  • p Visit previous historic version
  • n Visit next historic version
  • w Copy the abbreviated hash of the current historic version
  • W Copy the full hash of the current historic version
  • g Goto nth revision
  • q Exit the time machine.

Choose an issue against the current list in a commit buffer

With github, gitlab and others, it is possible to refer to a particular issue in a commit. So, in Emacs, it would be handy to pick our issue in the list of open issues, instead of remembering its id. This is possible with the git-commit-insert-issue package (only github at the moment), which will automatically fire an helm interface when it detects than we wrote something like "fixes #".

See also

See also the full list of packages to interact with Github, Gitlab and others in the Github page.

See a full list and a method to install them all at once on tarsiu's github page.