git merge

git

書き方

git merge [--no-ff|--squash] <branch>

別のブランチの作業を今のブランチに取り込みます。--squashは合流の記録を残さないので、そのブランチは後からも未マージ扱いのままです。

よく使うオプション

オプション意味
--no-ffalways record a merge commit, even when a fast-forward was possible
--ff-onlyrefuse unless it can fast-forward
--squashstage the combined change without committing or recording a merge
--abortundo a merge that stopped on conflicts
--continuefinish after you resolved the conflicts
-X ours|theirsauto-resolve conflicting hunks one way
--no-commitmerge but leave the commit to you

git merge --no-ff feature/login

keeps the branch visible in history

git merge --abort

gets you back to before the conflicted merge

git merge --squash feature/login

one flat change, staged; you still have to commit

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git merge は何をしますか。

別のブランチの作業を今のブランチに取り込みます。--squashは合流の記録を残さないので、そのブランチは後からも未マージ扱いのままです。

Q. どう打ちますか。

git merge [--no-ff|--squash] <branch> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは7個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-merge