LoginSignup
29
32

More than 3 years have passed since last update.

俺得Gitチートシート

Last updated at Posted at 2014-10-16

最初

$ git init
//README.mdと.gitignore作成
$ git add .
$ git commit -m”init”
//githubでレポジトリ作成
$ git remote add your_repo
$ git config branch.master.remote origin

remoteコマンド

参照しているremoteのURLと名前を確認・作成などができる

remote名 URL のような表記

  • 参照
    $ git remote -v

  • 追加
    $ git remote add your_repo

remoteのブランチと同期系

  • remoteの最新情報を取得、remoteで削除されたものはlocalでも削除する
    $ git fetch --prune

  • masterブランチが進んでいるときに追従する
    $ git pull -r

  • featureブランチが進んでいるときに追従する
    $ git pull remote名 branch名

  • すべてのremoteブランチ確認
    $ git branch -a

  • remoteをコピーしてローカルに作成
    $ git checkout -b local_branch_name origin/remote_branch_name

Stash

  • 保存
    $ git stash

  • メッセージ付き保存
    $ git stash save "メッセージ"

  • 一覧
    $ git stash list

  • 確認
    $ git diff HEAD..stash@{num}

  • 復元
    $ git stash pop stash@{num}

  • 削除
    $ git stash drop stash@{num}

  • 天変地異
    $ git stash clear

取り消しとか

  • ファイルの変更を取り消す(Revert的な)
    $ git checkout -- your_file

  • addしたファイルをステージングから取り消す
    $ git reset —-soft your_file(localはそのまま)
    $ git reset --hard your_file(localも戻る)

  • commitやり直し
    $ git commit --amend -m "new comment"

  • pushの上書き
    $ git push -f origin your_branch(あかん)

branch

  • リモートブランチ確認
    $ git branch -r

  • 全部のブランチ確認
    $ git branch -a

  • ブランチの削除
    $ git branch -d delete_branch

  • ブランチ名の変更
    $ git branch -m old-name new-name

  • ブランチの上書き
    $ git branch -f old-branch

コミットの順番を入れ替える

$ git rebase -i HEAD~num
コンフリクトしたら、内容を修正して
$ git rebase --continue

リモートのコミットを巻き戻す(取り扱い注意)

$ git push -f origin commit:remote_branch
戻ったら新しいcommitを
$ git push origin local_branch

既に管理しているファイルを無視したい

参考

変更を保持しない(cloneすると再度ファイルを読み込む)

  • 無視
    $ git update-index --assume-unchanged your_file

  • 無視解除
    $ git update-index --no-assume-unchanged your_file

変更を保持する(cloneしても上書きされない)

  • 無視
    $ git update-index --skip-worktree your_file

  • 無視解除
    $ git update-index --no-skip-worktree your_file

この辺の設定を確認
$ git ls-files -v

tag

  • 一覧表示
    $ git tag

  • 注釈付きタグの作成
    $ git tag -a v1.0.0

  • タグ情報の確認
    $ git show your_tag

rebaseのときのアレ

cherry-pick(コミットを採用)
reword(コミットを採用するが、コミットメッセージを変更)
edit(コミットを採用するが、ファイルを修正する)
squash(一個前のコミットと合体させる)
fixup(コミットメッセージを変更しない点以外、squashと同じ)
exec(shellでコマンドを実行する)

29
32
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
29
32