Changes between Version 15 and Version 16 of GitTips
- Timestamp:
- 05/01/2013 06:21:43 PM (10 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GitTips
v15 v16 5 5 This page is a collection of useful git tips. 6 6 7 == Apply a commit to multiple branches==7 == Merge a feature branch == 8 8 9 1. Checkout master branch 9 In 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 10 12 {{{ 11 13 #!sh 12 git checkout master14 git rebase -i develop 13 15 }}} 14 1. Make commit 16 17 1. Rebase your feature branch on top of current develop 15 18 {{{ 16 19 #!sh 17 git commit -m "Fixed bug"20 git rebase develop 18 21 }}} 19 1. Ch eckout stable branch22 1. Change to develop 20 23 {{{ 21 24 #!sh 22 git checkout stable25 git checkout develop 23 26 }}} 24 1. Apply the last commit from master to this branch27 1. `Fast-forward` merge your feature branch into develop 25 28 {{{ 26 29 #!sh 27 git cherry-pick master30 git merge myfeature 28 31 }}} 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 35 git branch -d myfeature 36 }}} 31 37 32 38 == Ignore changes in a tracked file == … … 101 107 }}} 102 108 109 110 == Undo the last commit == 111 ''Changes are put back into staged'' 112 {{{ 113 #!sh 114 git reset --soft HEAD~1 115 }}} 116 117 103 118 == Delete the last commit == 104 119 ''All changes are lost!'' 105 120 {{{ 106 121 #!sh … … 122 137 }}} 123 138 124 == Merge a topic branch==139 == Apply a commit to multiple branches with cherry-pick == 125 140 126 In this example we assume that your topic branch, <topic>, is off master and that you are currently in your topic branch 141 This technique uses cherry-pick to apply commits to branches that differ too much to use `merge`. 127 142 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 139 144 {{{ 140 145 #!sh 141 146 git checkout master 142 147 }}} 143 1. ('''Fast-forward''') merge your topic branch into master148 1. Make commit 144 149 {{{ 145 150 #!sh 146 git merge <topic>151 git commit -m "Fixed the bug that caused issue xyz" 147 152 }}} 148 1. Delete your local topic branch (see above tip for remote deletion)153 1. Checkout stable branch 149 154 {{{ 150 155 #!sh 151 git branch -d <topic>156 git checkout stable 152 157 }}} 158 1. Apply the last commit from master to this branch 159 {{{ 160 #!sh 161 git cherry-pick master 162 }}}