0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

大塚弘樹著 GitHub実践入門で学んだgitコマンド備忘録

Posted at

本について

本屋さんでGit関係の本を読みましたが、GitHubやGit Flowなどについてとても分かりやすく詳しく書かれているのでこちらを選びました。
いきなりgitに公開鍵を登録するのが序盤にあるので、GitHubを使うぞ!!という気持ちがとても伝わってきました。
著作権などに触れるとあれなので、大事なコマンドだけ抜き出してメモしておきます。

GitHub連携系

GitHubからクローン

 $ git clone git@github.com:ユーザー名/リポジトリ名.git

プッシュ

 $ git push -u origin リモートリポジトリのブランチ名

リモートリポジトリを登録

 $ git remote add origin git@github.com:ユーザー名/リポジトリ名

情報確認系

状況確認

 $ git status

バージョン管理系

リポジトリの初期化

 $ git init

ステージ(コミットできる状態にする)

 $ git add ファイル名

コミットする

コミットメッセージが1行のみ:
 $ git commit -m "メッセージ"

コミットメッセージが複数行:
 $ git commit

ステージとコミットを同時に行う

 $ git commit -am "コミットメッセージ"

直前のコミットメッセージを修正

 $ git commit --amend

コミットログの確認

通常
 $ git log

1行目だけ
 $ git log --pretty=short

指定したファイル・ディレクトリのみ
 $ git log ファイル・ディレクトリ名

ファイルの差分も確認
 $ git log -p

ブランチを視覚的に確認する
 $ git log --graph

作業ログの確認

 $ git reflog

戻る

とある場所に戻る(コミットや作業中のファイルなど、全てをその時点に戻す)
 $ git reset --hard ハッシュ

差分確認

最後にadd/コミットした場所 と 現在のファイル の差分
 $ git diff

最後のコミット と addされたファイル の差分
 $ git diff HEAD

履歴の改ざん

 $ git rebase -i HEAD~戻したい数
pick を fixup にすることで、その歴史を無かったことにする。

ブランチ関係

ブランチ一覧

 $ git branch

ブランチ切替

通常
 $ git checkout ブランチ名

ブランチを作成&切替
 $ git checkout -b ブランチ名

1つ前のブランチに戻る
 $ git checkout -

ブランチをマージ

引数についてわかりやすいサイトはこちら。

マージしたことを残しておく
 $ git merge --no-ff マージするブランチ名
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?