LoginSignup
148
148

More than 5 years have passed since last update.

EmacsのGitクライアント:Magit

Last updated at Posted at 2012-12-26

これはGitアドベントカレンダーの17日目のエントリーです。

このエントリーではEmacsのGitクライアントであるMagitの紹介を行います。ひよっこプログラマのエントリなので間違いがあれば指摘して下さい。逆に、ひよっこプログラマだからこそ出来る、これを見たら初心者でも出来るようなエントリを目指しました。

Magitって何?

EmacsのGitクライアントです。Emacsでコード編集して、ターミナルに移動せずそのままEmacs上でGitの操作を行うことが出来ます。

インストール方法

ソースはgithubで公開されています。
https://github.com/magit/magit
インストールします。

    $ cd
    $ mkdir tmp
    $ cd tmp
    $ git clone git@github.com:magit/magit.git
    $ cd magit
    $ ./configure
    $ make
    $ sudo make install

で、.emacs.d/init.elに次の記述を追加します。

    (require 'magit)

これだけ!

チュートリアル

とりあえずgit管理下のファイルを開いている状態で、 git statusに対応するM-x magit-statusしてみましょう。すると

Remote:   master @ origin (git@github.com:takc923/dotfiles.git)
Local:    master ~/dotfiles/
Head:     88b780e modified init.el and elscreen.el for emacs24

Changes:                                                                                                                              
    Modified   .emacs.d/init.el

こんな画面が現れます。カーソルをModified .emacs.d/init.elの行に移動し、Tabキーを押すと

Local:    master ~/dotfiles/
Head:     88b780e modified init.el and elscreen.el for emacs24

Changes:
    Modified   .emacs.d/init.el
diff --git a/.emacs.d/init.el b/.emacs.d/init.el
index b0db796..103a40f 100644
--- a/.emacs.d/init.el                                                                                                               
+++ b/.emacs.d/init.el                                                                                                               
@@ -1,5 +1,6 @@
 ;; .emacs                                                                                                                           

+                                                                                                                                    
 ; path                                                                                                                              
 (setq load-path (cons "~/.emacs.d/site-lisp" load-path))  

diffが見れます。変更が正しいことを確認したら、ファイルの行でsを押します。

Remote:   master @ origin (git@github.com:takc923/dotfiles.git)
Local:    master ~/dotfiles/
Head:     88b780e modified init.el and elscreen.el for emacs24

Staged changes:
    Modified   .emacs.d/init.el

Stageされました(git add .emacs.d/init.elと同じ効果)。今はChangesなファイルが1つですが、複数ある時はSで全てStage出来ます。

次にcを押すと、新しくwindowが現れます。ここでcommitコメントを書いてC-c C-cを入力するとcommit出来ます。

Remote:   master @ origin (git@github.com:takc923/dotfiles.git)
Local:    master ~/dotfiles/
Head:     dd0f21c test

Unpushed commits:
dd0f21c * test

commit出来ました。次にgit pullを行います。git pullするにはgit-status画面でFを入力します。すると

Switches
-r: Rebase (--rebase)
Actions
F: Pull

という画面が現れます。git pull --rebaseするなら-rと入力します。すると--rebaseの色が変わるので、その後Fを押すとpull出来ます。pullする前にもう一度-rを入力すると--rebaseの色が戻り普通のpullが出来ます。
すると、パスフレーズが聞かれるので入力します。

Password for '/home/takc923/.ssh/id_rsa': ……………

pullが完了しました。
次にpushします。pushするにはmagit-status画面でPを押します。すると

Switches
 -f: Force (--force)      -d: Dry run (-n)         -u: Set upstream (-u)
Actions
P: Push         t: Push tags

という画面が現れます。ここもpull同様、オプションをつけるなら-f,-d,-uしてからPを入力します。やっぱりパスフレーズを聞かれるので入力するとpush出来ます。

チュートリアルは以上です。

終わりに

magitのインストール方法と、簡単な使い方だけ紹介しました。これから使う人の入り口になれば幸いです。もちろんmagitでは他にも色んな操作が可能です。ここから先は以下の参考ページや、magitでぐぐって出てきたエントリを参考に使ってみてください。
参考
http://magit.github.com/magit/magit.html

148
148
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
148
148