littlewing

人間とコンピューターとメディアの接点をデザインするために考えたこと

gitでよく使うけど忘れるやつ

  • ファイルを指定して、そのファイルを特定のcommitまで戻す
git checkout {戻したいcommmitID} {相対ファイル名}
  • 直前のコミット操作を取り消す
git reset --soft HEAD^
  • 最新から、<commit>までの差分をarchive zip化
git archive --format=zip --prefix=<ProjectName>/ HEAD  `git diff --name-only <commit>`  -o archive.zip
  • remote のbranchを削除
$ git push --delete origin {branch_name}
  • local に新規branch作成
#一覧を取得
git branch -a
 
#作成元のbranchに移動
git checkout {master} 

#新しいbranchを作成
git checkout -b {new_branch}
  • 特定のコミット間の対象フォルダを指定して変更ファイル名の一覧を取得する
 git diff --stat --name-only --relative=<対象フォルダ> <commitID1> <commitID2>

git rm -r --cached .
git add .
git commit
git push
  • SJISファイルのdiff をサクッと見たい
 git diff | iconv -f SJIS
  • master の更新を hogebranchに取り込む
※ もし、作業途中のものでcommit出来るものがあればcommitしておく
# masterブランチへ移動
git checkout master

# git pullでmasterを最新に
git pull origin master
# 開発用ブランチへ移動
git checkout hogebranch
# mergeコマンドでmaserの内容を取り込む
git merge origin master

Submodule

  • submoduleを消す
git submodule deinit path/to/submodule
 git rm path/to/submodule
  • 強制的にsubmoduleのmaster branchを反映させる
git submodule foreach git pull origin master