LoginSignup
0
3

More than 5 years have passed since last update.

Gitの基本コマンド

Posted at

Gitの基本まとめ。
image.png

image.png

<ローカルリポジトリ>

image.png

gitを使えるようにする

$ git init

ステージングエリアに上げる

$  git add {filneName}

.: ディレクトリ内すべて

ローカルリポジトリに上げる

$ git commit -m "message"
$  git commit --amend
$ git commit -am "message"

コミットのログを見る

$ git log

--oneline: ログを一行で表示
-p: git diffを同時に表示
--stat: 変更したファイルの情報を表示

現在の状況を見る

$ git status

変更点を確認

作業ディレクトリにあるファイルの変更点を確認

$ git diff

--cached: ステージングエリアにあるファイルの変更点を確認

gitの管理に特定のファイルを含めない方法

.gitignore
*.log

commitを戻す時

直前のcommitに戻す

$ git reset --hard HEAD

3番目のcommitに戻す

$ git reset --hard HEAD^

指定した{commitID}まで戻す

$ git reset --hard {commitID}

resetを取り消す

ひとつ前のresetをキャンセルする

$ git reset --hard ORIGIN_HEAD

branch

branch listを表示

$ git branch

branchを作成

$ git branch {branchName}

branchを切り替え

$ git checkout {branchName}

branch作成から切り替えまで行ってくれる

$ git branch -b {branchName}

marge

今いるbranchに{branchName}を反映させる

$ git marge {branchName}

branchを削除

$ git branch -d {branchName}

tag

tag listを表示

$ git tag

tagを作成

$ git tag {tagName}

tagを付与

$ git tag {tagName} {commitID}

tagを削除

$ git tag -d {tagName}

alias

コマンド名を短縮して登録

$ git config --global alias.co checkout
$ git config --global alias.st status
$ git config --global alias.br branch
$ git config --global alias.ci commit

alias listを表示

$ git config -l

<リモートリポジトリー>

image.png

リモートリポジトリーを設定

$ git init --bare

リモートリポジトリの追加

$ git remote add {remoteRepositoryName} {remoteRepository's absolutePath}               

{remoteRepositoryName} = origin など

リモートリポジトリーに上げる

$ git push {remoteRepositoryName} {localBranchName}

{remoteRepositoryName} = origin, {localBranchName} = master

リモートリポジトリーに上がっている内容を作業ディレクトリにコピペする

$ git clone {remoteRepository's absolutePath} {directoryName}

リモートリポジトリーにあるファイルの変更点を作業ディレクトリにあるファイルにも反映させる

$ git pull {remoteRepositoryName} {localBranchName}

{remoteRepositoryName} = origin, {localBranchName} = master

参考

【Git入門!】Gitって何?から基本的な使い方までを簡単解説

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