1. Gitの管理系コマンド
Gitでの操作履歴確認、リポジトリファイル名の確認など、管理系のコマンドについて纏めます。
2. 確認コマンド
2-1. 現在の状態(変更履歴)を確認する
$ git status
ファイル修正などを何もしていない場合
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
ファイル修正などを行っている場合(README.mdを修正した場合)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
2-2. コミットの履歴を確認する
git logコマンドを利用する事で、過去に実施したコミット内容を確認できる。
$ git log
commit 1097a4158b39e36f5092c89 (HEAD -> master, origin/master)
Author: hashihei
Date: Sun Jun 23 20:31:00 2019 +0000
file delete.
logは通常1画面に表示できない程大量にある為、以下の操作コマンドを利用して確認する。(他のキーバインドでも同等操作可能なものもあります)
| No. | キーバインド | 操作内容 |
|---|---|---|
| 1 | h | ヘルプを表示する |
| 2 | q | ログ確認の終了 |
| 3 | j | 1行下(先)へ進む |
| 4 | k | 1行上(前)へ戻る |
| 5 | f | 1画面分下(先)へ進む |
| 6 | b | 1画面分上(前)へ戻る |
| 7 | q | ヘルプの終了 |
2-3. コミットの履歴を確認する(1行表示)
$ git log --oneline
1b939c0 add new file.
4e1b30c create function.
2-4. コミットの内容を確認する
最新のコミット内容を確認する
$ git show
git logコマンド等で確認したコミットタグを指定して内容を確認する。
$ git show [commit tag id]
2-5. 利用リポジトリ情報を確認する
$ git config -l
~
user.email=yourmail
user.name=username
~
remote.origin.url=https://github.com/[username]/***.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
2-6. gitファイルの移動
gitに登録したファイルを移動させる場合は、以下のコマンドを利用する。
$ git mv [path from] [path to]
2-7. リモートリポジトリ一覧の確認
登録されているリモートリポジトリの一覧を確認するには以下のコマンドを利用する。
$ git remote
origin
リポジトリのURLなどを確認するにはshowコマンドを用いる。
$ git remote show origin
* remote origin
Fetch URL: https://github.com/[username]/****.git
Push URL: https://github.com/[username]/****.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
2-8. リモートリポジトリの追加
originとしてgithubを利用しているが、Bitbucketも利用している場合などは、以下のコマンドでリモートリポジトリを追加する。
$ git remote add [username] [remote repository PATH]
2-9. ファイル編集内容を確認する
$ git diff
3. 日本語マニュアル
公式日本語マニュアルは以下から確認できます。 Git manual v2