20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

GitAdvent Calendar 2015

Day 2

Gitのmanページとか読んでみよう

Last updated at Posted at 2015-12-01

突然ですがみなさんgitの使い方に困った時、どうしてますか?"git force push しちゃった"とかいってググっちゃいますか?
10時間に渡るフライト中、読書もしたし昼寝もしたし、やることがなくなった時、どうしてますか?

そんな時は是非、gitのmanページとか読んでみましょう。

$ man git
GIT(1)                                                       Git Manual                                                      GIT(1)

NAME
       git - the stupid content tracker
       

まずは冒頭です。gitはバカ構成管理システムなんですね。知りませんでした。

SYNOPSIS
       git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]
           

manページの最初に必ず載っているのがこのSYNOPSISです。慣れないと何を言っているのかわからないかもしれませんが、下記のようなルールを押さえておくと読めると思います。

[必須でないオプションや引数]
<必須の引数>

ここを読むだけで、そのコマンドの使い方はだいたい分かってしまうというわけです。

DESCRIPTION
       Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both
       high-level operations and full access to internals.

続いて概要の説明があります。何はともかくgitはサイコーであると言ってます。

       See gittutorial(7) to get started, then see giteveryday(7) for a useful minimum set of commands. The Git User's Manual[1]
       has a more in-depth introduction.

       After you mastered the basic concepts, you can come back to this page to learn what commands Git offers. You can learn more
       about individual Git commands with "git help command". gitcli(7) manual page gives you an overview of the command-line
       command syntax.

       Formatted and hyperlinked version of the latest Git documentation can be viewed at
       http://git-htmldocs.googlecode.com/git/git.html.

初学者がどうやってgitを習得すれば良いか、ドキュメントの場所も含めて丁寧に導いてくれています。素晴らしいですね。ドキュメントにこれだけ力を入れてくれていると知りたい情報にすぐにたどり着けるので、本当に助かります。
なおgittutorial(7) というのはgittutorialのsection-7のmanページという意味です。gittutorialのmanページはsection-7しかないようなので、man gittutorial で参照することができました。


続いて。

OPTIONS
       --version
           Prints the Git suite version that the git program came from.

       --help
           Prints the synopsis and a list of the most commonly used commands. If the option --all or -a is given then all available
           commands are printed. If a Git command is named this option will bring up the manual page for that command.

           Other options are available to control how the manual page is displayed. See git-help(1) for more information, because
           git --help ...  is converted internally into git help ....

ここから各オプションの説明に入っていきます。
--versionはいいとして、--help をよく見てください。--all-aを併用すると、すべてのコマンドが表示されるが、そうでなければ 一番よく使うコマンド が一覧表示されると書いてあります。

実際にやってみましょう。

$ git --help
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone      Clone a repository into a new directory
   init       Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add        Add file contents to the index
   mv         Move or rename a file, a directory, or a symlink
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
   bisect     Use binary search to find the commit that introduced a bug
   grep       Print lines matching a pattern
   log        Show commit logs
   show       Show various types of objects
   status     Show the working tree status

grow, mark and tweak your common history
   branch     List, create, or delete branches
   checkout   Switch branches or restore working tree files
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   merge      Join two or more development histories together
   rebase     Forward-port local commits to the updated upstream head
   tag        Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch      Download objects and refs from another repository
   pull       Fetch from and integrate with another repository or a local branch
   push       Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
$ git --help -a
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

available git commands in '/usr/local/Cellar/git/2.6.3/libexec/git-core'

  add                       merge-index
  add--interactive          merge-octopus
  am                        merge-one-file
  annotate                  merge-ours
  apply                     merge-recursive
  archimport                merge-resolve
  archive                   merge-subtree
  bisect                    merge-tree
  bisect--helper            mergetool
  blame                     mktag
  branch                    mktree
  bundle                    mv
  cat-file                  name-rev
  check-attr                notes
  check-ignore              p4
  check-mailmap             pack-objects
  check-ref-format          pack-redundant
  checkout                  pack-refs
  checkout-index            patch-id
  cherry                    prune
  cherry-pick               prune-packed
  citool                    pull
  clean                     push
  clone                     quiltimport
  column                    read-tree
  commit                    rebase
  commit-tree               receive-pack
  config                    reflog
  count-objects             relink
  credential                remote
  credential-cache          remote-ext
  credential-cache--daemon  remote-fd
  credential-store          remote-ftp
  cvsexportcommit           remote-ftps
  cvsimport                 remote-http
  cvsserver                 remote-https
  daemon                    remote-testsvn
  describe                  repack
  diff                      replace
  diff-files                request-pull
  diff-index                rerere
  diff-tree                 reset
  difftool                  rev-list
  difftool--helper          rev-parse
  fast-export               revert
  fast-import               rm
  fetch                     send-email
  fetch-pack                send-pack
  filter-branch             sh-i18n--envsubst
  fmt-merge-msg             shell
  for-each-ref              shortlog
  format-patch              show
  fsck                      show-branch
  fsck-objects              show-index
  gc                        show-ref
  get-tar-commit-id         stage
  grep                      stash
  gui                       status
  gui--askpass              stripspace
  hash-object               submodule
  help                      svn
  http-backend              symbolic-ref
  http-fetch                tag
  http-push                 unpack-file
  index-pack                unpack-objects
  init                      update-index
  init-db                   update-ref
  instaweb                  update-server-info
  interpret-trailers        upload-archive
  log                       upload-pack
  ls-files                  var
  ls-remote                 verify-commit
  ls-tree                   verify-pack
  mailinfo                  verify-tag
  mailsplit                 web--browse
  merge                     whatchanged
  merge-base                worktree
  merge-file                write-tree

git commands available from elsewhere on your $PATH

  branch-by-author        lfs
  credential-osxkeychain  subtree

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.

-aをつけると、見たこともないコマンドがたくさん出てきますね。でも、臆することはありません。--helpの解説にあるように、git <command> --help とすることで、懇切丁寧なドキュメントを瞬時に参照することができるからです。

いかがでしたでしょうか?
皆さんも気が向いた時にはぜひgitのmanページとかhelpを開いてみてください。

20
18
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
20
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?