| 66 | |
| 67 | However, from time to time the repository is updated (by the administrator). You however have all branches that are local still branching from the now outdated versions. How to remedy that? |
| 68 | |
| 69 | ==== ... updating your branches ==== #exchanging-repo-update |
| 70 | |
| 71 | Let us assume that your branch is called ''!MyBranch'' and branches of ''v0.9.9'' and the administrator has updated the branch ''stable'' such that it no longer coincides with ''v0.9.9'' but with ''v1.0.0''. Also, I assume that you have remote (see above) called '''jupiter''' that is the repository administrated by the administrator. |
| 72 | |
| 73 | First of all, pull the changes in (remote) branch ''stable'' from jupiter and merge the changes into your (local) branch ''stable''. |
| 74 | {{{ |
| 75 | git checkout stable |
| 76 | git pull jupiter stable |
| 77 | }}} |
| 78 | |
| 79 | Now your local branch is updated, as you can see in |
| 80 | {{{ |
| 81 | gitk --all |
| 82 | }}} |
| 83 | |
| 84 | However, as you also can see, ''!MyBranch'' now branches off from the old version ''v0.9.9'' and not from updated ''stable'' at ''v1.0.0''. What you need to do is '''rebase''' your commits from the first till the current one and place them on top of branch ''stable''. This can be achieved in one go via '''git rebase --onto ...'''. |
| 85 | |
| 86 | For this to work, you need to know three pieces of information: |
| 87 | * where to rebase onto, here it's simply ''stable'', i.e. the updated branch |
| 88 | * begin~1 ..., where the ~1 indicates that it should by the one commit before your first (e.g. ''v0.9.9'' if it branched off the old ''stable'' at ''v.0.9.9''). This can be easily got from inside '''gitk''', you just have to copy the ''<hash>''. |
| 89 | * ... and end of your branch, here it is ''!MyBranch''. |
| 90 | |
| 91 | Note again that the the interval of your commits to replay on top of the now current ''stable'' has to be given as ''[first-1, last]'', where ''first'' is your first and ''last'' your last commit, i.e. we need the one commit before (If you are unsure, select the hash code of your first commit and add ''~1'' to it. You may check whether it's the correct one via |
| 92 | {{{ |
| 93 | git log <hash>~1 |
| 94 | }}} |
| 95 | Log should display none of your commits but only immediately up till your last one. |
| 96 | |
| 97 | Then execute |
| 98 | {{{ |
| 99 | git rebase --onto stable <hash> MyBranch |
| 100 | }}} |
| 101 | and git will replay each of your commit on top of the current ''stable'' branch. |
| 102 | |
| 103 | It may happen that changes in your branch and changes occuring between ''v0.9.9'' and ''v1.0.0'' coincide. This will cause an interruption, a so-called conflict, and git will ask you to fix this by yourself. |
| 104 | {{{ |
| 105 | git status |
| 106 | }}} |
| 107 | gives you all files that have been modified from both sides (i.e. you and the administrator). |
| 108 | |
| 109 | Edit the files and you see lines like these |
| 110 | {{{ |
| 111 | ... |
| 112 | <<<<<<<<<< HEAD |
| 113 | size_t index = 0; // this was changed by admin |
| 114 | ========== |
| 115 | size_t index = INDEX_NULL; // this was changed by you |
| 116 | >>>>>>>>>> |
| 117 | ... |
| 118 | }}} |
| 119 | You have to decide (for your local branch) which are the appropriate changes, i.e. eventually it may look like this |
| 120 | {{{ |
| 121 | ... |
| 122 | size_t index = INDEX_NULL; // this was changed by you |
| 123 | ... |
| 124 | }}} |
| 125 | because your changes are the correct ones. |
| 126 | |
| 127 | After editing all files and fixing all this conflicts, type |
| 128 | {{{ |
| 129 | git add <file> |
| 130 | }}} |
| 131 | where '''<file>''' is a list of changed files, and continue the rebase with |
| 132 | {{{ |
| 133 | git rebase --continue |
| 134 | }}} |
| 135 | |
| 136 | If it stops with more conflicts, fix them in the same way as above, until you have successfully performed the rebase. |
| 137 | |
| 138 | Now your branch ''!MyBranch'' is up-to-date, as '''gitk''' will show you when you reload its database. |
| 139 | |