LoginSignup
20
22

More than 5 years have passed since last update.

Git コマンド

Last updated at Posted at 2018-02-09

Gitコマンド

最近コマンドgit管理しようと勉強しているので、よく使うコマンドメモ

ブランチ一覧 作成 移動 削除 

git branch                        //ローカルブランチ一覧

git branch -r                     //リモートブランチ一覧

git branch --merged               //マージ済み

git branch --no-merged            //未マージ一覧

git branch -a                    //全ブランチ一覧

git checkout <branch_name>        //ブランチ移動

git checkout -b <branch_name>     //新規ブランチ作成

git branch --delete <branch_name> //ブランチ削除

git branch -D <branch_name>       //強制削除

リモートブランチからブランチ作成(例)

git branch -r

結果
hogehoge
testtest

git checkout -b hogehoge origin/hogehoge

変更内容確認

git diff HEAD //前回変更分からの差分

変更取消

git checkout <filename> //指定のファイルの変更取消
git checkout .          //全てのファイルの変更を取り消し

**どちらもファイルの追加または削除の取り消しはできないので注意**

ファイルステージにアップ

git status         //アップロードファイル確認

git add .          //全てのファイルをファイルステージにアップ

git add <filename> //指定したファイルをアップ

ファイルステージ取り消し

git reset HEAD <filename> //指定したファイル名のアップを取り消し

git reset HEAD .          //全てのファイルのアップを取り消し

コミット操作

git commit -a           //変更のあったファイルすべて

git commit --amend      //直前のコミットを取り消す

git commit -v           //変更点を表示してコミット

git reset --soft HEAD~2 // 最新のコミットから2件分をワークディレクトリの内容を保持し取り消す

git reset --hard HEAD~2 // 最新のコミットから2件分のワークディレクトリの内容とコミットを取り消す

マージ

git merge <branch_name>

プッシュ

git push origin <branch_name>

一時退避

git stash

git stash pop //戻す

git stash list //退避一覧

git stash clear //退避削除

ログ確認

log --graph --date-order --all --pretty=format:'%h %Cred%d %Cgreen%ad %Cblue%cn %Creset%s' --date=short

git作成

git init
git remote add origin <url> // オリジナルがここですよ。
git fetch
git pull origin  master // オリジナルのmasterを引っ張ってこい。
git pull origin branchname // ブランチを引っ張ってる時はこちら。
git checkout branchname // 引っ張って来たブランチに切り替える。

随時更新していきます。

20
22
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
20
22