LoginSignup
0
2

More than 5 years have passed since last update.

Gitの森を歩く

Last updated at Posted at 2017-04-16

参考にしたもの
https://git-scm.com
http://dev.classmethod.jp/tool/git/hub/

Gitコマンド

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

git remote add origin <repository>

githubの場合

git remote origin git@github.com:kentakozuka/sample.git

リポジトリの登録を削除

git remote rm origin

リモートリポジトリのブランチへのプッシュと削除

<remote-repository>リポジトリの<remote-branch>ブランチに<local-branch>ブランチをプッシュする

git push <remote-repository> <local-branch>:<remote-branch>

ブランチ名が同じ場合は省略可能

git push origin master

は以下と同じ

git push origin master:master

以下のようにするとoriginリポジトリのsampleブランチを削除できる

git push origin :sample

これは

git push origin <empty-branch>:sample

と考えればよい

フェッチ

トラッキングブランチを最新にする。
リモートブランチ(origin)から最新の情報を取ってきて、トラッキングブランチ(origin/master)を更新する

git fetch origin

マージ

(git checkout <branch-to-be-merged>)
git merge <branch-to-merge>

masterブランチにworkブランチをマージする場合

(git checkout master)
git merge work

マージコミットを残す

git merge work --no-ff

プル

リモートブランチからフェッチしてマスターブランチ(master)へマージする

git pull origin

以下と同じ

(git checkout master)
git fetch origin
git merge origin/master

ブランチを作成

git branch <new-branch> <original-branch>

現在いるブランチから新しいブランチを作成する場合

git branch <new-branch>

ブランチの削除

git branch -d <branch>

ステージングをキャンセル

git rm --cached ファイル名

diff

ブランチ間

git diff [ブランチ名A] [ブランチ名B]

インデックスと作業ディレクトリの差分

git diff

HEADとインデックス

git diff –cache

2つのコミット

git diff [COMMITID1] [COMMITID2]

ファイル指定

git diff [FILE]

コミット

コミットを新しい順に表示

git log

コミットの取り消し

3つの重要なオプション
--soft
コミットだけ

--mixed (デフォルト)
コミットとインデックス

--hard
コミット・インデックスに加え、ワークディレクトリの内容も書き換える

直前のコミットの取り消し

git reset HEAD^

直前のコミットに上書き

git commit --amend

hubコマンド

hubコマンドをgitコマンドで使用できるようにする
evalでhub alias -sが展開されてalias git=hubとなる

vim .bashrc
...
eval "$(hub alias -s)"
...

アカウントの設定

GitHub の Settings の中にある Personal access tokens にて生成

---
github.com:
- protocol: https
  user: <ユーザ名>
  oauth_token: <トークン>

hub pull-request

cliからプルリクエストを作成する

hub pull-request -b <upstream-repo>:<branch> -h <downstream-repo>:<branch>

エディタが立ち上がる
1行目がタイトル
2行目は空白
3行目からが本文

vim fugitive

ステータスを見る

:Gstatus

差分を見る

:Gstatusの一覧画面でD

0
2
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
2