LoginSignup
0
1

More than 1 year has passed since last update.

git コマンド集

Last updated at Posted at 2021-06-17

gitのコマンド

・git バージョン管理

現在のバージョンを確認できる!

$ git --version 

・git バージョンの更新

$ brew update

上記の作業が終わってから、下記も行う!!!

$ brew install git

git 名前・メール・atom 設定

・githubのユーザー名
$ git config --global user.name"github user name"
・メールアドレス
$ git config --global user.email 登録したメールアドレス
・atomの設定
$ git config --global core.editor "atom --wait"

ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
設定した内容の確認
$ git config --list 

git ファイルの内容を確認

cat ~/.gitconfig

git よく使用するコマンド

・cdコマンド
ディレクトリを移動します。

・lsコマンド
ディレクトリの内容を表示します。 ls -a コマンドで、隠しファイルを含めたディレクトリ全内容を表示します。

・mkdirコマンド
ディレクトリを新規作成します。

・rmコマンド
ファイルを削除します。

・cpコマンド
ファイルをコピーします。

・mvコマンド
ファイルの移動とファイル名の変更を行います。

・catコマンド
ファイルの中身を表示します。

Mac/ターミナル/ローカルリポジトリを行う

どこでフォルダーを作成するか確認すること!!!
フォルダーの場所まで移動して下記を行う!!!

・フォルダーを作成
$ mkdir フォルダー名

・作成したフォルダーに移動
$ cd  フォルダー名

・フォルダー内にgitに必要なファイルを作成
$ git init       //.git/が作成されその中にファイルが作成される!

・フォルダーに中身の確認
$ ls -a

・gitの中身を確認
$ ls .git/
→HEAD config  hooks   objects refs  

リポジトリのコピーを行う 開発で参加する際に

GithubからCodeのコピーを行い、下記に貼り付ける!

$ git clone https://github.com/___________.git

gitステージの変更

$ git add ファイル名
$ git add フォルダー名
$ git add .

gitのコミット コマンド

$ git commit
$ git commit -m "<メッセージ>"  //エディターを立ち上げずに行える
$ git commit -v   //変更内容を確認ができる

変更されたファイルの状況の確認

$ git status

git 変更差分を確認する

・git addする前の変更の確認ができる!!
$ git diff
$ git diff ファイうめい

・git addした後の変更に確認ができる!!
$ git diff --staged

git 変更履歴を確認する

・変更全てを確認
$ git log

・1行で表示する
$ git log --oneline

・特定ファイルの変更履歴を確認
$ git log -p ファイル名

・最近の変更履歴を確認できる
$ git log -n 数字    //最近のコミットが 【記述した数字分】 確認できる!!

git ファイルの削除を記録する

・ファイルごと削除
$ git rm ファイル名
$ git rm -r ディレクトリ名

・ファイルを残したとき        //リポジトリ側だけ削除
$ git rm --cached ファイル名

------------------------------------------------
・ファイルを復活させるには、下記2つのコマンドを行う!!!
$ git reset HEAD ファイル名
$ git checkout ファイル名

git ファイルの移動を記録する

・ファイル名を変更
$ git mv 旧ファイル 新ファイル

・以下も同じコマンド
$ mv 旧ファイル 新ファイル
$ git rm 旧ファイル
$ git add 新ファイル

リモートリポジトリを新規追加/githubへ送信

$ git remote add origin https://github.com/_____________/repo.git

.githubへ送信
$ git push リモート名 ブランチ名
$ git push origin master 
↓
$ git push -u origin master  
//-uオプションを使用すると、次回以降git pushのみで使用可能

git コマンドにエイリヤスをつける

・入力が楽になる!!! コマンドが長いものに対して使用しやすい!!!
--globalを付けることで、【PC全体の設定】になる!!!

$ git config --global alias.ci commit  //commitは、git ciのみでできるようになる
$ git config --global alias.st status  
$ git config --global alias.br branch
$ git config --global alias.co checkout
→$ git ci  (git commit)
→$ git st  (git status)
→$ git br  (git branch)
→$ git co  (git checkout)

gitの管理から外す/ファイルを管理しない/ファイルを見せない

パスワードなど、gitに載せたくないファイルに対して行う!!!
.gitignoreファイルに指定する。

$ vim .gitignore  //ファイルを作成

設定ができるようになるので、iコマンドを押して、insertに変更し隠したい拡張子を設定
*.拡張子
*.php
*.js    など

最後にesc- :wqで終了する
$ git status で確認すること

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