LoginSignup
42
44

More than 3 years have passed since last update.

よく使うGitCommandを超カンタンにまとめてみた

Last updated at Posted at 2020-09-04

よく使うGitCommand

ローカルリポジトリの生成

git init

変更されたファイルの一覧を表示

git status

index.htmlをステージングに上げる

git add index.html

変更をコミット

git commit -m "initial commit"

最後のコミットまで戻す

git checkout -- .

過去のコミットの内容を新しい順から一覧で表示

git log

拡張子がpngのファイルをステージングに上げる

git add *.png

cssフォルダ内にあるすべてのファイルをステージングに上げる

git add css/

pdfフォルダ内にある拡張子がpdfのファイルをステージングに上げる

git add pdfs/*.pdf

すべての編集済みファイルをステージングに上げる

git add -A

拡張子がxmlのファイルをステージングから下ろす

git reset *.xml

コミットログを一行で表示する

git log --oneline

ファイルの状態をわかりやすく表示する

git status -s

拡張子がxmlのファイルをステージングから下ろす(作業ブランチを表示)

git status -s -b

エリアスの設定(git log をインラインで表示するエリアス)

git config --global alias.lg "log --oneline --decorate --all --graph"

エリアスの設定(git status)

git config --global -e

Gitコンフィグの情報を表示する

git config --global -l
git config --global -e

最後のコミットとローカルファイルでの変更差分を表示する

git diff

最後のコミットとステージングに上がっているファイルの変更差分を表示する

git diff --staged

ステージングに上がっているREADME.mdをステージングから下ろす

git reset HEAD README.md

README.mdファイルの変更を戻す

git checkout -- README.md

addとcommitを同時にする

git commit -am "Readme actualz"

コミットメッセージの修正

git commit --amend -m "Actualizamos el readme"

既にあるコミットの修正を修正しなおす。

git reset --soft HEAD^
git commit -am "Actualizamos el readme con todos los archivos a omitir"

マルチラインでコミットを行う

git commit

指定したコミットの状態に戻す

git reset --mixed 860c6c2

指定したコミットの状態に戻したあとに、その先のコミットを捨てる

git reset --hard 860c6c2

HEADのログを表示

git reflog

ファイルの移動(リネーム)

git mv destruir-mundo.txt salvar-mundo.txt

ファイルの削除

git rm salvar-mundo.txt

新しく追加されたファイルは追加されず、変更・削除されたファイルのみがステージングに追加される

git add -u

新しいブランチを作る

git branch rama-hoge

新しいブランチを作成すると同時にそのブランチに移動する

git branch -b rama-hoge

ローカルブランチの一覧

git branch

rama-hoge と master (ブランチ間)の差分を表示

git diff rama-hoge master

masterローカルブランチに移動

git checkout master

今いるブランチとrama-hogeブランチをマージする(Fast-Forward)

git merge rama-hoge

ローカルブランチとリモートブランチの一覧を表示する

git branch -a

rama-hogeローカルブランチを削除する

git branch -d rama-hoge

rama-hogeリモートブランチを削除する

git push origin :rama-hoge

githubからブランチを削除した場合にローカルに残るリモートブランチの情報を削除する

git remote prune origin

Tagの付与

git tag superRelease

Tagの一覧

git tag

Tagを削除

git tag -d superRelease

コメント付きタグ付与

git tag -a v1.0.0 -m "Version 1.0.0"

タグと任意コミットハッシュを紐付ける(コメント付き)

git tag -a v0.1.0 345d7de -m "Version alfa"

タグv1.0.0の詳細情報を表示

git show v1.0.0

現時点の変更をStash(退避)する

git stash
 //or
git stash save

Stashの一覧を表示する

git stash list

最後にStashしたものを戻す

git stash apply

任意のStashを戻す(StashID指定)

git stash apply stash@{1}

最後のStashを戻した後にStashから削除

git stash pop

Stashを削除

git stash drop

ステージングに上がっているファイル以外をStashする

git stash save --keep-index

addしていないファイルも含めてStashする

git stash save --include-untracked

全てのStashの情報を表示

git stash list --stat

最後にStashしたドキュメントの情報を表示

git show stash

指定したStashの情報を表示

git show stash@{1}

コメント付きStash

git stash save "Agregamos Comment"

Stashを全て削除

git stash clear

リモートリポジトリをクローンする

git clone https://github.com/DiegoAlessandro/XXXX.git

リモートリポジトリの向き先を表示する

git remote -v

ローカルにあるTagをリモートリポジトリに上げる

git push --tags

リモートリポジトリの最新をローカルに持ってくる(自動マージ)

git pull

リモートリポジトリの最新をローカルに持ってくる(自動マージをしない)

git fetch

フォーク元のリポジトリを参照する

git remote add upstream https://github.com/DiegoAlessandro/XXXXX.git

フォーク元リポジトリのMasterブランチからプルする

git pull upstream master
42
44
2

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
42
44