LoginSignup
0
0

More than 3 years have passed since last update.

git あれこれ

Posted at

事前知識

よく使うやつ

- git add
- git commit
- git commit --amend # コミットを修正
- git log
- git show ハッシュ値
- git blame ファイルパス # そのファイルを編集した人を確認できる
- git reset --soft HEAD~ # コミットしてしまったモノをインデックスに戻す
- git branch -a # リモートブランチの一覧確認
- git rebase
  - conflictになった場合
    - >>> でソース検索して、コンフリクト個所を修正
    - git add . # 修正をインデックスに入れる
    - git rebase --continue # この繰り返し
- gitの設定ファイル
 - ~/.gitconfig  # ここを編集すると passwordを求められrない

手を動かしながら学習できるやつ

commit周り

  • commit までしてしまった変更内容を確認する
 git log -p -1
  • commitをしてしまったのを戻す
git reset --soft HEAD~1

リモートブランチ削除

# リモートブランチ確認
git brach -a

# 対象のブランチ削除
git push origin :hoge 
※closeになっている

# 手順
1.prの内容をコピーしてオク
2.ローカルのブランチ名変更
3.リモートブランチを削除する
4.再度 push

検索色々

git squash

  • commitをまとめるモノ

git 設定

git config
https://qiita.com/shionit/items/fb4a1a30538f8d335b35

git 設定ファイル場所

~/.gitconfig

ブランチ名変更

git branch -m <古いブランチ名> <新しいブランチ名>

リモートブランチ削除

git push --delete origin branch_name

特定のコミットまで戻る

$ git reset --hard ハッシュ値

git blame

git blame  パス → ハッシュ値取得

git show ハッシュ値 → PR検索可能

ファイルの行毎に履歴を確認する

git log --grep=検索文字列

initail commot

git commit --allow-empty -m "first commit"

amend

git commit --amend
:wq
修正漏れでコミットできていない時

add取り消し

git reset HEAD spec/models/product_spec.rb

git commit indexに戻す

git reset --soft HEAD~

conflictを解除する

git add .
git rebase --continue

cherry-pick修正内容だけ持ってくる

git cherry-pick 24838567ab060b430194fa6123a59ffa2f3589f2

  • フロー

branchA ←コピーしたいブランチのハッシュ値を調べる git logで

branchA-2を作成する

gc branchA-2

git cherry-pick ハッシュ値 of 24838567ab060b430194fa6123a59ffa2f3589f2

git branch  -D branchA

git branch -m branchA-2 branchA

解決法

$ rm -f .git/index.lock

git 特定のコミットまでもどしたい

git reset --hard 90c3ef40fe27c02331c5ad76937dbcad0b1003f9
0
0
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
0
0