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:22] – [Squashing] 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 | ||
| </ | </ | ||
| Line 231: | Line 238: | ||
| ==== Fast-forwarding ==== | ==== Fast-forwarding ==== | ||
| + | |||
| + | Recall a fast-forward merge: | ||
| + | |||
| + | < | ||
| + | A---B---C topic | ||
| + | / | ||
| + | D---E | ||
| + | </ | ||
| + | |||
| + | You may or may not want that: | ||
| < | < | ||
| Line 302: | Line 319: | ||
| </ | </ | ||
| - | ===== Setting | + | ===== Setting |
| - | You can set per-branch merge options | + | ==== Per-branch merge options |
| + | |||
| + | From '' | ||
| < | < | ||
| - | $ git config --global branch.master.mergeOptions "--squash" | + | 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 "--no-ff" | ||
| + | </ | ||
| + | |||
| + | ==== 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 | ||
| </ | </ | ||