gitコマンド

2018/6/6

git - プログラムのソースコードなどの変更履歴を記録・追跡するための分散型バージョン管理システムである。

$ git  [オプション]  <コマンド> [<args>] <ENTER>
オプション 機能の説明
add ファイルやディレクトリをインデックスに登録する
status ワーキングツリーの状態を表示する
log コミットログをを表示する
show 様々なオブジェクトの情報を表示する
rm ワーキングツリーからファイルを削除する
diff コミット間の差分やコミットとワーキングツリーの差分を表示する
push リモートリポジトリにプッシュする
pull リモートリポジトリからプルする
grep マッチングしたパターンを表示する
reset 現在のHEADをリセットする
config リポジトリまたはグロバルのオプションを取得・設定する
remote
clone リモートリポジトリをクローンする
branch ブランチを表示・作成・削除する
init 空のリポジトリを作成または既存のリポジトリを初期化する
help 使用法を出力して終了します。
–version バージョン情報を表示して終了する

オプション config

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

オプション add

$ git add .
$ git add crontab*.sh 
$ git add ./www/\*.html

オプション status

$ git status 
$ git status --short
$ git status --branch 
$ git status --verbose

オプション log

$ git log
$ git log --graph
$ git log --decorate
$ git log --oneline
$ git log --source
$ git log --grep=<pattern>

オプション remote

$ git remote -v

オプション show

$ git show

オプション reset

$ git reset --soft HEAD

$ git reset --hard HEAD

$ git push origin -f

オプション push

$ git push

オプション pull

$ git pull

オプション clone

$ git clone ssh://[user@]host.xz[:port]/path/to/repo.git/
$ git clone git://host.xz[:port]/path/to/repo.git/
$ git clone http[s]://host.xz[:port]/path/to/repo.git/
$ git clone ftp[s]://host.xz[:port]/path/to/repo.git/

$ git clone /path/to/repo.git/
$ git clone file:///path/to/repo.git/

オプション diff

$ git diff
$ git diff <コミットID2> <コミットID1>
$ git diff HEAD^ HEAD^^

オプション branch

$ git branch

オプション init

$ git init

$ git init --bare

オプション help

$ 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     Reapply commits on top of another base tip
   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.

オプション –version

$ git --version
git version 2.17.1