#author("2022-11-12T02:13:20+09:00","","")
#author("2022-11-12T12:24:36+09:00","","")
#topicpath

///////////////////////////////////////////////////////////////////////////////
* 目次 [#t01cbf77]
#contents();
#ls2(VersionCtl/git/magit/);

///////////////////////////////////////////////////////////////////////////////
* 導入方法(v.3.2.1) [#t81f6c56]
- magit 本体を取得。
-- https://github.com/magit/magit.git
- 追加で以下が必要となる。
-- https://github.com/magnars/dash.el.git
-- https://github.com/magit/with-editor.git
-- https://github.com/magit/magit-popup.git
-- https://github.com/vermiculus/graphql.el.git
-- https://github.com/magit/git-modes.git
-- https://github.com/volrath/treepy.el.git
-- https://github.com/magit/ghub.git
- ${HOME}/.emacs.d/site-lisp/ 配下に手動インストールした場合の設定例。
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/dash") load-path))
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/with-editor") load-path))
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/magit-popup") load-path))
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/graphql") load-path))
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/treepy") load-path))
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/ghub") load-path))
 (setq load-path (cons (expand-file-name "~/.emacs.d/site-lisp/magit/lisp") load-path))

//=============================================================================
** compile [#l532a7e5]
- 依存パッケージ(dash, transient, with-editor)へのパス指定が必要。
-- 指定方法
 magit/config.mk:
 LOAD_PATH  = -L ~/.emacs.d/site-lisp/magit/lisp
 LOAD_PATH += -L ~/.emacs.d/site-lisp/dash
 LOAD_PATH += -L ~/.emacs.d/site-lisp/transient/lisp
 LOAD_PATH += -L ~/.emacs.d/site-lisp/with-editor
--- see also: magit/Documentation/magit.info



- graphql 
-- make を実行するのに、yq (jq の wrapper。[[yqの入手元(GitHub)>https://github.com/kislyuk/yq]])、及び jq が必要になる。
-- jq は debian なら jq パッケージで導入可。

///////////////////////////////////////////////////////////////////////////////
* コマンド version 3.2.1 [#x82b682c]
|~binding |~command        |~description            |~remark |
| b       |magit-branching |ブランチ操作 | |
| y       |magit-show-refs-popup |ブランチ一覧 | |
| C-j     |magit-diff-visit-worktree-file | | |
| C       |magit-commit-add-log | | |
| K       |magit-file-untrack | | |
| R       |magit-file-rename | | |
| a       |magit-apply | | |
| s       |magit-stage | | |
| u       |magit-unstage | | |
| <C-return> |magit-diff-visit-file-worktree | | |
| <remap>                      |Prefix Command | | |
|C-c C-e  |magit-diff-edit-hunk-commit | | |
|C-c C-t  |magit-diff-trace-definition | | |
| <remap> <magit-delete-thing> |magit-discard | | |
| <remap> <magit-revert-no-commit> |magit-reverse | | |
| <remap> <magit-visit-thing>  |magit-diff-visit-file | | |
|C-x a                         |magit-add-change-log-entry | | |
|C-x 5 <return>                |magit-diff-visit-file-other-frame | | |
|C-x 4 a                       |magit-add-change-log-entry-other-window | | |
|C-x 4 <return>                |magit-diff-visit-file-other-window | | |

- 各 pop-up ウインドウを抜ける時は、 "q" → "C-g" へ変更になった。
- 各 pop-up ウインドウ表示中、カーソルキー、ウインドウ間移動(other-window, previous-other-window)は無効化されるようになった。

*** Major Mode Bindings: [#j47ae25e]
|~binding |~command |~remark |
| C-c |Prefix Command | |
| TAB |magit-section-toggle | |
| RET |magit-visit-thing | |
| C-w |magit-copy-section-value | |
// | C-x |Prefix Command | |
| ESC |Prefix Command | |
| SPC |magit-diff-show-or-scroll-up | |
| !   |magit-run | |
| $   |magit-process-buffer   | |
| %   |magit-worktree         | |
| +   |magit-diff-more-context | |
| -   |magit-diff-less-context | |
| 0   |magit-diff-default-context | |
| 1   |magit-section-show-level-1 | |
| 2   |magit-section-show-level-2 | |
| 3   |magit-section-show-level-3 | |
| 4   |magit-section-show-level-4 | |
| 5 .. 9  |digit-argument | |
| :   |magit-git-command | |
| <   |beginning-of-buffer | |
| >   |end-of-buffer | |
| ?   |magit-dispatch | |
| A   |magit-cherry-pick |git cherry-pic の操作メニューを表示 |
| B   |magit-bisect | |
| D   |magit-diff-refresh | |
| E   |magit-ediff |git diff の操作メニューを表示する |
| F   |magit-pull |pull の操作メニュー・・・は表示されないが、 &br;''F u'': magit-pull-from-upstream &br;''F p'': magit-pull-from-pushremote &br;''F e'': magit-pull-branch &br;がそれぞれ実行出来る。  |
| G   |magit-refresh-all | |
| I   |magit-gitignore | |
| L   |magit-log-refresh | |
| M   |magit-remote |git remote の操作メニューを表示する |
| O   |magit-subtree | |
| P   |magit-push |git push の操作メニューを表示 |
| S   |magit-stage-modified | |
| T   |magit-notes | |
| U   |magit-unstage-all |stage されている全てのファイルを unstage する |
| V   |magit-revert | |
| W   |magit-patch | |
| X   |magit-reset |git reset の操作メニューを表示する |
| Y   |magit-cherry      | |
| Z   |magit-stash |git stash の操作メニューを表示する |
| ^   |magit-section-up  | |
| b   |magit-branch | |
| c   |magit-commit |git commit の操作メニューを表示する |
| d   |magit-diff | |
| e   |magit-ediff-compare | |
| f   |magit-fetch | |
| g   |magit-refresh | |
| h   |magit-dispatch | |
| i   |magit-gitignore | |
| j   |magit-status-jump | |
| k   |magit-delete-thing | |
| l   |magit-log |git log の操作メニューを表示する |
| m   |magit-merge | |
| n   |magit-section-forward | |
| o   |magit-submodule | |
| p   |magit-section-backward | |
| q   |magit-mode-bury-buffer | |
| r   |magit-rebase | |
// | s  |magit-stage-file   |選択中のファイルを stage する |
| t   |magit-tag    |git tag の操作メニューを表示する |
// | u  |magit-unstage-file |選択中のファイルを unstage する |
| v   |magit-revert-no-commit | |
| w   |magit-am | |
| x   |magit-reset-quickly | |
| y   |magit-show-refs |branch 操作の操作メニューを表示。機能としては v.2.1.0 での magit-branch-popup に近い。 |
| z   |magit-stash |git stash の操作メニューを表示 |
| DEL       |magit-diff-show-or-scroll-down | |
| S-SPC     |~| |
| <C-tab>   |magit-section-cycle | |
| <M-tab>   |magit-section-cycle-diffs | |
| <backtab> |magit-section-cycle-global | |
| <remap>   |Prefix Command | |
| <s-tab>   |magit-section-cycle-global | |
| <remap> <dired-jump> |magit-dired-jump | |
// | j f |Prefix Command | |
// | j n |magit-jump-to-untracked | |
// | j p |Prefix Command | |
// | j s |magit-jump-to-staged | |
// | j t |magit-jump-to-tracked | |
// | j u |magit-jump-to-unstaged | |
// | j z |magit-jump-to-stashes | |
| C-c C-c |magit-dispatch | |
| C-c C-o |magit-browse-thing | |
| C-c C-w |~| |
// | C-x 4   |Prefix Command | |
// | C-x a   |magit-add-change-log-entry | |
// | M-RET   |magit-dired-jump | |
| C-M-i |magit-dired-jump | |
| M-w   |magit-copy-buffer-revision | |
| M-1   |magit-section-show-level-1-all | |
| M-2   |magit-section-show-level-2-all | |
| M-3   |magit-section-show-level-3-all | |
| M-4   |magit-section-show-level-4-all | |
| M-n   |magit-section-forward-sibling | |
| M-p   |magit-section-backward-sibling | |
// | M-w |magit-copy-buffer-revision | |
// | <remap> <evil-next-line> |evil-next-visual-line | |
// | <remap> <evil-previous-line> |evil-previous-visual-line | |
// | j p p |magit-jump-to-unpushed-to-pushremote | |
// | j p u |magit-jump-to-unpushed-to-upstream | |
// | j f p |magit-jump-to-unpulled-from-pushremote | |
// | j f u |magit-jump-to-unpulled-from-upstream | |
// | C-x 4 a |magit-add-change-log-entry-other-window | |



//=============================================================================
** diff [#za81b8f5]
- リポジトリと差分のあるファイルのファイル名の上で "e" を type すると、emacs の ediff を利用した差分編集画面が起動する。
- この diff の画面は、ある時期に 2ペインから3ペインに変更されているが、これは "e" に割り当てられた関数が変更されたため。
|~画面 |~関数 |
|2ペイン |magit-ediff-compare |
|3ペイン |magit-ediff-dwim |
- 最新の magit で、差分編集を以前の2ペインにしたい場合は、magit を読み込んだあとの方で、以下を記述する
 (define-key magit-mode-map "e" 'magit-ediff-compare)
-- これで、若干面倒ではあるが(その代わり比較対象をどのブランチにするかなど、手動で都度選べるようにもなる)、2ペインの diff が使えるようになる。
-- 但し、conflict 解決の場合に magit-diff-compare を起動すると、(マージや rebase による)conflict 前後の比較ではなく、conflict した結果と現在の HEAD との比較となってしまう。この場合には magit-ediff-dwim を起動するようにする。~
→ ''"e"'' と ''"E"'' で両者を使い分けると良いだろう。


///////////////////////////////////////////////////////////////////////////////
* ユースケース [#i8b933a0]
//=============================================================================
** 部分ステージング&コミット [#f188710b]
** 部分ステージング&コミット [#partical-staging-commit]
+ M-x: magit-status を実行
+ ''Unstaged changes'' にリストされているファイルの内、部分ステージング&コミットしたいファイルにカーソルを置き、 [Tab] 押し → 差分が展開される
+ 部分ステージング&コミットしたい差分のところにカーソル移動(p/n で Jump する)し、s 押し。
+ magit 上での通常の commit 操作と同じ c, c, C-c で commit される。


///////////////////////////////////////////////////////////////////////////////
* 設定 [#ec895f87]
//=============================================================================
** log の日付表示設定 [#r4e6a952]
- magit-log では、"1 week", "2 years" などと大まかな時期での表示となっており、日時での確認が出来ない。
- 日時での表示に切り替えるには、${HOME}/.emacs.d/init.el 等で以下を設定する:
 (eval-after-load "magit-log"
   '(progn
      (custom-set-variables
       '(magit-log-margin '(t "%Y-%m-%d %H:%M:%S " magit-log-margin-width t 18)))))
- 上記でフォーマット文字列の最後に空白文字を入れているのは、表示される文字と表示領域の境界との間を少し間を空けたかった為。

//=============================================================================
** log の commit ID の表示色の設定 [#n24e1876]
- default では暗目のグレーになっており、黒背景の場合には非常に見難い。そのような環境で使用する場合には以下のように変更する:
 (custom-set-faces
  '(magit-hash ((t (:foreground "white")))) ; log の commit ID 文字色
  ;'(magit-section-highlight ((t (:background "blue")))) ; highlight
  )

//-----------------------------------------------------------------------------
*** 参考リンク [#kb186367]
- [[magitのログを、コミット時期ではなくコミット時刻で表示したい>https://qiita.com/hiroxy/items/5d2146b8a1a84a454e55]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS