git-mergeã§--ff(ããã©ã«ã)ã¨--no-ffã¨--squashã®éã
ãã£ãã
A successful Git branching model » nvie.com
ãããããããè¦ã¦ã--no-ffã¤ãã¨ãããããã ãªã¼ã¨æ·±ãèããã«ä½¿ã£ã¦ããã--squashã¤ããã¨å®å
¨ã¨ããªãã¨ããã©èããã¦æ··ä¹±ãã¾ãã£ãã®ã§èª¿ã¹ã¦ã¿ãã
ã¨ããããmanã
man git-merge
...
--ff, --no-ff
Do not generate a merge commit if the merge resolved as a fast-forward, only update the branch pointer. This is the default behavior of git-merge.
With --no-ff Generate a merge commit even if the merge resolved as a fast-forward.
...
--squash, --no-squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not
actually make a commit or move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit command 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.
...
ãã¼ããªãã¨ãªãããããããªæ°ããããã©ãã¤ãã¤ãããããããã®ã§è©¦ãã¦ã¿ãã
è±èªããã¡ãªã ãã¨ãè¨ãã
試ãã¦ã¿ã
ã2ãã¨ããã³ãããã¡ãã»ã¼ã¸ã®ãã°ãæã¤masterããb1ãã©ã³ããä½ãã¾ãã
fast-forward*1ãªç¶æ
ã§b1ããmergeãããã®ã§ãé©å½ã«1ãã¡ã¤ã«addãã¦ãã4ãã¨ã¡ãã»ã¼ã¸ãå
¥ãã¾ãã
ã³ãããã¡ãã»ã¼ã¸ã®æ°åãé£çªãããªãã®ã¯ä»ã®åä½æ¤è¨¼ããã¦ãã®ã§â¦ã¡ãã»ã¼ã¸ç°¡ç¥åãããã¦ãããããã¥ããã£ãããã
(ãã°ã¯ã¦ã¼ã¶ååé¤ã¨ãã§æ´å½¢ãã¦ãã®ã§å®éã®è¡¨ç¤ºã¨ã¯ç°ãªãã¾ã)
ãã¼ã¸å
masterãã©ã³ã
* 2f1eea2 2011-03-10 | 2 (HEAD, master)
b1ãã©ã³ã
* 28031c0 2011-03-10 | 4 (HEAD, b1)
git merge b1ã§ãã¼ã¸ (--ffåä½)
ãã°
* 28031c0 2011-03-10 | 4 (HEAD, master, b1) * 2f1eea2 2011-03-10 | 2
git merge --no-ff b1ã§ãã¼ã¸
* 54627d3 2011-03-10 | Merge branch 'b1' (HEAD, master) |ã½ | * 28031c0 2011-03-10 | 4 (b1) |/ * 2f1eea2 2011-03-10 | 2
git merge --squash b1ã§ãã¼ã¸
* 2f1eea2 2011-03-10 | 2 (HEAD, master)
ããï¼ãã°ããã¼ã¸åã¨å¤ãããªãã
git statusãã¦ã¿ãã¨â¦Changes to be committed:ã«ã³ãããã¡ãã¼ã¸ã4ãã§ä¿®æ£ãããã¡ã¤ã«ããã£ãã
ã¨ãããã¨ã§ã--squashã¯ãã¼ã¸ããçµæãã³ã³ããªã¯ããç¡ãã¦ãã¯ã¼ã¯ããªã¼ã«å±éãã¦ããã®å¾èªåã§ã³ããããã模æ§ã
ã¡ãªã¿ã«è¤éã«ãªãã®ã§ä¸ã§ãã¿ã¼ã³ã«ã¯å
¥ãã¦ãªããã©ã以ä¸åä½ãçæã®äºã
- ã³ã³ããªã¯ããããã¨ãã¯ãªãã·ã§ã³ã«é¢ãããèªåçã«ã³ããããããªãã(--squashç¸å½ã®åä½)
- --ffã§ãfast-forwardãããªãã¨ãã¯ãã¼ã¸ã³ããããã§ããã
- --no-ffã§ãã¼ã¸ã³ããããä½ã£ã¦ããã°ãgit revert HEADãããgit reset HEAD^ãã§ãã¼ã¸ãç¡ãã£ããã¨ã«ããã®ã¯ç°¡åã
ã¾ã¨ã
ã¨ãããã¨ã§â¦
- ã¡ãã£ã¨ããåãè¾¼ã¿ã«ã¯ãªãã·ã§ã³ç¡ã(--ff)
- æ»ãæãããããã¼ã¸ã§ãã¼ã¸ã³ããããå¿ ãä½ãããã¨ãã¯--no-ff
- æ¹å¤ãã¦åãè¾¼ãå¿ è¦ãããã¨ãã«--squash
ã¨ããããã«ä½¿ãåããã¨è¯ããã¨ç解ãéã£ããææãã ããã
gitã¯æ©è½è±å¯ã§æ¦å¿µãè¤éã§å«æ°ãããäºããããã©ãç解ããã¨ãã³ãã«ä¾¿å©ã§ããï¼
ã¾ã ã¾ã ããããç¥ããªãæ©è½ããã¨æãã¾ããã©ãâ¦
*1:ãã¼ã¸å¯¾è±¡ãã©ã³ããèªãã©ã³ãã®ã³ããããå ¨ã¦æã£ã¦ãã=ãã¼ã¸ããåç´ã«åãããã®ã¿