Changes between Version 15 and Version 16 of GitTips


Ignore:
Timestamp:
05/01/2013 06:21:43 PM (11 years ago)
Author:
Cas
Comment:

update tips

Legend:

Unmodified
Added
Removed
Modified
  • GitTips

    v15 v16  
    55This page is a collection of useful git tips. 
    66 
    7 == Apply a commit to multiple branches == 
     7== Merge a feature branch == 
    88 
    9  1. Checkout master branch 
     9In this example we assume that your feature branch, `myfeature`, is based off `develop` and that you are currently in your feature branch. 
     10 
     11 1. Squash/reword/edit any commits if need be 
    1012{{{ 
    1113#!sh 
    12 git checkout master 
     14git rebase -i develop 
    1315}}} 
    14  1. Make commit 
     16 
     17 1. Rebase your feature branch on top of current develop 
    1518{{{ 
    1619#!sh 
    17 git commit -m "Fixed bug" 
     20git rebase develop 
    1821}}} 
    19  1. Checkout stable branch 
     22 1. Change to develop 
    2023{{{ 
    2124#!sh 
    22 git checkout stable 
     25git checkout develop 
    2326}}} 
    24  1. Apply the last commit from master to this branch 
     27 1. `Fast-forward` merge your feature branch into develop 
    2528{{{ 
    2629#!sh 
    27 git cherry-pick master 
     30git merge myfeature 
    2831}}} 
    29  1. Repeat steps 3-4 as necessary 
    30  1. PROFIT! 
     32 1. Delete your local feature branch (see above tip for remote deletion) 
     33{{{ 
     34#!sh 
     35git branch -d myfeature 
     36}}} 
    3137 
    3238== Ignore changes in a tracked file == 
     
    101107}}} 
    102108 
     109 
     110== Undo the last commit == 
     111''Changes are put back into staged'' 
     112{{{ 
     113#!sh 
     114git reset --soft HEAD~1 
     115}}} 
     116 
     117 
    103118== Delete the last commit == 
    104  
     119''All changes are lost!'' 
    105120{{{ 
    106121#!sh 
     
    122137}}} 
    123138 
    124 == Merge a topic branch == 
     139== Apply a commit to multiple branches with cherry-pick == 
    125140 
    126 In this example we assume that your topic branch, <topic>, is off master and that you are currently in your topic branch 
     141This technique uses cherry-pick to apply commits to branches that differ too much to use `merge`. 
    127142 
    128  1. Squash/reword/edit any commits if need be 
    129 {{{ 
    130 #!sh 
    131 git rebase -i master 
    132 }}} 
    133  1. Rebase your topic branch on top of current master 
    134 {{{ 
    135 #!sh 
    136 git rebase master 
    137 }}} 
    138  1. Change to master 
     143 1. Checkout `master` branch 
    139144{{{ 
    140145#!sh 
    141146git checkout master 
    142147}}} 
    143  1. ('''Fast-forward''') merge your topic branch into master 
     148 1. Make commit 
    144149{{{ 
    145150#!sh 
    146 git merge <topic> 
     151git commit -m "Fixed the bug that caused issue xyz" 
    147152}}} 
    148  1. Delete your local topic branch (see above tip for remote deletion) 
     153 1. Checkout stable branch 
    149154{{{ 
    150155#!sh 
    151 git branch -d <topic> 
     156git checkout stable 
    152157}}} 
     158 1. Apply the last commit from master to this branch 
     159{{{ 
     160#!sh 
     161git cherry-pick master 
     162}}}