LoginSignup
31
27

More than 5 years have passed since last update.

git使い始めて1ヶ月くらいでこれだけ覚えてたらなんとかなった

Last updated at Posted at 2015-12-03

前提

新しいプロジェクトで初めてgitを使ってみて、とりあえずこれだけ覚えてたらなんとかなったよ、というコマンド一覧です :smiley:
特殊な操作は期待できませんが、最近やり始めて「あれ、これってどうするんだっけ」という基本的な操作の参考になれば幸いです。(考えかた等は割愛しています)

Git(GitBash)

Setting

$ git config --global user.name "hoge hoge" //name
$ git config --global user.email hogehoge@hoge.com //Email
$ git config --global core.quotepath false //日本語表示
$ git config --global core.autocrlf false //改行コード
$ git config --(global/sysytem/local) --l

First

$ cd <gitリポジトリをつくるところ>
$ git clone http://…/hogehoge.git //初回のみ

Routine

リポジトリ名[hogehoge]に移動する

$ cd hogehoge

作業するブランチを切る(必要な場合)

$ git branch <ブランチ名>
$ git branch //一覧&今いるブランチ表示
  • ブランチ名の変更
//ブランチを指定して変更
$ git branch -m <旧ブランチ名> <新ブランチ名>

//今いるブランチを変更
$ git branch -m <新ブランチ名> 
  • ブランチの削除
$ git branch -d <ブランチ名>

修正後、addしてindexにのせて/commitして確定させて/pushする

$ git add
$ git commit -m "コメント"
$ git push

他人の修正をワークスペースに反映させる(随時)

$ git pull

[add] Details

リポジトリに登録されていて変更されたソースをindexに追加する

$ git add -u //削除されたソース〇、新規のソース×

ワークツリーの変更と新しく作成されたファイルをリポジトリに登録する

$ git add -A //削除されたソース〇、新規のソース〇

Return(ワークスペースの変更取消)

$ git checkout [ファイルパス/.]

Return(add取消)

$ git reset HEAD [ファイルパス/.]

Return(commit取消)

ワークスペースの変更は保持する

$ git reset --soft HEAD^
$ git add [ファイルパス/.] //修正
$ git commit -a -c ORIG_HEAD

ワークスペースの変更も取り消す

$ git reset --hard HEAD^
$ git add [ファイルパス/.] //修正
$ git commit -a -c ORIG_HEAD

上書き修正する

$ git commit // まちがえたcommit
$ git add [ファイルパス/.] //修正
$ git commit --amend //commitを修正

Merge

他人がpushしたソースを自分も修正していた場合、commit前にワークスペースに反映する(git pullでエラーがでた場合)

  • 自分の変更を一旦gitから見えない状態にする
$ git stash save "コメント"
$ git stash list //一覧表示
  • ワークスペースが修正前の状態になるのでpullしてまず他人のcommitを反映する
$ git pull
  • 隠していた自分の変更を反映させる(merge処理が走る)
$ git stash pop
$ git status
Changes to be committed:
 ⇒merge成功したソース一覧
 自動的にaddされる
Unmerged paths:
 ⇒merge失敗したソース一覧
 該当ソースをひらいて手動で修正&addすること
  • 修正が完了したらcommit/pushする
$ git commit
$ git push
  • 隠していたものを削除する
$ git stash drop

- git stash pop でエラーが出たらインデックスに変更を加える

error: Your local changes to the following files would be overwritten by >merge:
some_file
Please, commit your changes or stash them before you can merge.
Aborting
Index was not unstashed.

$ git add -u

History

$ git log
31
27
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
31
27