LoginSignup
1
0

More than 3 years have passed since last update.

Github

Posted at

ブランチ マージ

ブランチ
並行して複数機能を開発するための仕組み
大本のブランチ master

HEADは現在作業している所
ブランチを新規作成する

ブランチの切り替えまでは行われない
$git buranch ブランチ名

ブランチの表示
$git buranch

全て表示 リモートブランチも表示
$git buranch -a

ブランチの切り替え
$git checkout 既存のブランチ名


新規作成+ブランチの切り替え
$git checkout -b ブランチ名

ブランチを変更削除
変更
$git branch -m ブランチ名
削除
$git buranch -d ブランチ名 masterにマージされていない変更は残る

$git buranch -D ブランチ名 強制的に削除

マージ
統合

$git merge ブランチ名
$git merge リモート名/ブランチ名


    b = masterブランチ
  - b
a
  - c
  c = testブランチ


  マージすると
  - b     d = masterブランチ
a      - d
  - c
  c = testブランチ


----------------------

Fast Foward


master    test
↓         ↓
a  ----   b


        master
        test
↓         ↓
a  ----   b

--------------------

Auto Merge



  b = masterブランチ
  - b
a
  - c
  c = testブランチ


親を2つ持っている b c を持っている
  - b     d = masterブランチ
a      - d
  - c
c = testブランチ


-----------------------------------------
コンフリクト

b c 同じ箇所を修正した場合に起こる

  b = masterブランチ
  - b
a
  - c
  c = testブランチ



複数人で同じファイルを編集しないようにする

変更中の状態をなくす事
  pull mergeを行う前に commit stashをしておくこと

pullを行う際に ブランチを確認してから行う


実践編

プルリクエスト


ワークツリー
masterブランチを最新にする
ブランチファイルを作成
ファイルを編集変更
変更をコミット

ローカルリポジトリへプッシュ
↓
ローカルリポジトリ
プルリクエスト
コードレビューしてもらう
プルリクエストマージ
ブランチ削除

$git checkout -b pull_request
$git branch
master
*pull_request
$git add.
$git commit -m'pull_request create'
$git push origin pull_request


githubサイトへ


File changesでコードを見ることが出来る
紫でdeletedを押す

$git branch -d pull_request
または-D


github_flow

pull_request
maerge
 繰り返し



rebase

test
- b
a
- c
master
```

$git checkout test
$git rebase master
```

a - c - b`になる
master test

github pushしたコミットをリベースするのはNG

git push -fは使用するべきではない
強制的に行えるがgitがくしゃくしゃになるため行わないようにする

リベースとマージどっちを使用するべき?

マージ
コンフリクト○
マージコミットがたくさんあると複雑

作業履歴を残したいなら

リベース
履歴がきれいに保つ
コンフリクト△

履歴をきれいに使うなら

プッシュ後したあと
コンフリクトしそうならマージを使用

プッシュしていないローカルの変更に対してはリベース

ローカル関係はリベース それ以外はマージ

コミットをきれいに整えてからの
pushをする場合の履歴の書き換え方
pushしていないコミットのみ

直前のコミットをやり直す

$git commit --amend


直前のコミットをやり直す



複数のコミッtのやり直し


ステージベース

$git rebase -i commitID
$git rebase -i HEAD~2       /2/3/4/5/5

edit as268da
pick wadfg45s
pick fdhnb513


editに変更すればそこまで戻る

$git commit --amend


$git rebase --continue




$git stash apply


ステージの状態も復元する場合
$git stash apply --index



特定の作業を復元する場合
$git stash applay スタッシュ名



$git stash drop
$git stash スタッシュ名


全作業削除
$git stash clear
ー=
1
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
1
0