Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| git_merge [2019/03/06 15:12] – [SYNOPSIS] rpjday | git_merge [2019/03/13 13:09] (current) – [Global merge.ff option] rpjday | ||
|---|---|---|---|
| Line 66: | Line 66: | ||
| / | / | ||
| D---E | D---E | ||
| + | </ | ||
| + | |||
| + | or, depicted another way: | ||
| + | |||
| + | < | ||
| + | D---E---A---B---C master | ||
| + | topic | ||
| </ | </ | ||
| ===== Query containedness and mergeness ===== | ===== Query containedness and mergeness ===== | ||
| + | |||
| + | From '' | ||
| < | < | ||
| Line 224: | Line 233: | ||
| Welcome to the second edition of the Pro Git book. | Welcome to the second edition of the Pro Git book. | ||
| ... etc ... | ... etc ... | ||
| + | </ | ||
| + | |||
| + | ===== Advanced merging ===== | ||
| + | |||
| + | ==== Fast-forwarding ==== | ||
| + | |||
| + | Recall a fast-forward merge: | ||
| + | |||
| + | < | ||
| + | A---B---C topic | ||
| + | / | ||
| + | D---E | ||
| + | </ | ||
| + | |||
| + | You may or may not want that: | ||
| + | |||
| + | < | ||
| + | --ff | ||
| + | When the merge resolves as a fast-forward, | ||
| + | branch pointer, without creating a merge commit. This is | ||
| + | the default behavior. | ||
| + | |||
| + | --no-ff | ||
| + | Create a merge commit even when the merge resolves as a | ||
| + | fast-forward. This is the default behaviour when merging an | ||
| + | annotated (and possibly signed) tag that is not stored in | ||
| + | its natural place in refs/tags/ hierarchy. | ||
| + | |||
| + | --ff-only | ||
| + | Refuse to merge and exit with a non-zero status unless the | ||
| + | current HEAD is already up to date or the merge can be | ||
| + | resolved as a fast-forward. | ||
| + | </ | ||
| + | |||
| + | ==== Committing ==== | ||
| + | |||
| + | < | ||
| + | --commit, --no-commit | ||
| + | Perform the merge and commit the result. This option can be | ||
| + | used to override --no-commit. | ||
| + | |||
| + | With --no-commit perform the merge but pretend the merge | ||
| + | failed and do not autocommit, to give the user a chance to | ||
| + | inspect and further tweak the merge result before | ||
| + | committing. | ||
| + | </ | ||
| + | |||
| + | ==== Editing ==== | ||
| + | |||
| + | < | ||
| + | --edit, -e, --no-edit | ||
| + | Invoke an editor before committing successful mechanical | ||
| + | merge to further edit the auto-generated merge message, so | ||
| + | that the user can explain and justify the merge. The | ||
| + | --no-edit option can be used to accept the auto-generated | ||
| + | message (this is generally discouraged). The --edit (or -e) | ||
| + | option is still useful if you are giving a draft message | ||
| + | with the -m option from the command line and want to edit | ||
| + | it in the editor. | ||
| + | </ | ||
| + | |||
| + | ==== Squashing ==== | ||
| + | |||
| + | < | ||
| + | --squash, --no-squash | ||
| + | Produce the working tree and index state as if a real merge | ||
| + | happened (except for the merge information), | ||
| + | actually make a commit, move the HEAD, or record | ||
| + | $GIT_DIR/ | ||
| + | to create a merge commit). This allows you to create a | ||
| + | single commit on top of the current branch whose effect is | ||
| + | the same as merging another branch (or more in case of an | ||
| + | octopus). | ||
| + | |||
| + | With --no-squash perform the merge and commit the result. | ||
| + | This option can be used to override --squash. | ||
| + | </ | ||
| + | |||
| + | As in: | ||
| + | |||
| + | < | ||
| + | $ git checkout master | ||
| + | $ git merge --squash <branch with many commits> | ||
| + | $ git commit | ||
| + | </ | ||
| + | |||
| + | ===== Setting merge options ===== | ||
| + | |||
| + | ==== Per-branch merge options ==== | ||
| + | |||
| + | From '' | ||
| + | |||
| + | < | ||
| + | branch.< | ||
| + | Sets default options for merging into branch < | ||
| + | syntax and supported options are the same as those of git- | ||
| + | merge(1), but option values containing whitespace | ||
| + | characters are currently not supported. | ||
| + | </ | ||
| + | |||
| + | For example, if you wanted to prevent any fast-forward merges to any '' | ||
| + | |||
| + | < | ||
| + | $ git config --global branch.master.mergeOptions " | ||
| + | </ | ||
| + | |||
| + | ==== Global merge.ff option ==== | ||
| + | |||
| + | For merging, there is at least one repo-wide merge option you can set (see '' | ||
| + | |||
| + | < | ||
| + | merge.ff | ||
| + | By default, Git does not create an extra merge commit when | ||
| + | merging a commit that is a descendant of the current | ||
| + | commit. Instead, the tip of the current branch is | ||
| + | fast-forwarded. When set to false, this variable tells Git | ||
| + | to create an extra merge commit in such a case (equivalent | ||
| + | to giving the --no-ff option from the command line). When | ||
| + | set to only, only such fast-forward merges are allowed | ||
| + | (equivalent to giving the --ff-only option from the command | ||
| + | line). | ||
| + | </ | ||
| + | |||
| + | So for widespread fast-forward merge configuration: | ||
| + | |||
| + | < | ||
| + | $ git config --global merge.ff " | ||
| + | </ | ||
| + | |||
| + | This setting is superseded by any per-branch fast-forward merge setting. | ||
| + | |||
| + | ===== Merge strategies ===== | ||
| + | |||
| + | ==== ours ==== | ||
| + | |||
| + | Technically record a merge while totally ignoring its content -- for record-keeping. | ||
| + | |||
| + | Example: | ||
| + | |||
| + | < | ||
| + | $ git checkout master | ||
| + | $ git merge --strategy=ours < | ||
| + | </ | ||
| + | |||
| + | How to make '' | ||
| + | |||
| + | < | ||
| + | $ git checkout topic | ||
| + | $ git merge -s ours master | ||
| + | $ git checkout master | ||
| + | $ git merge --ff-only topic | ||
| + | </ | ||
| + | |||
| + | To do this for an arbitrary commit, create a temporary branch: | ||
| + | |||
| + | < | ||
| + | $ git checkout -b tempbranch <commit ID> | ||
| + | $ git merge -s ours master | ||
| + | $ git checkout master | ||
| + | $ git merge --ff-only tempbranch | ||
| </ | </ | ||