Changes for page Git
Last modified by Richard Kreissig on 2025/01/30 12:03
Summary
-
Page properties (1 modified, 0 added, 0 removed)
-
Objects (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -158,7 +158,7 @@ 158 158 It is also possible to create a branch and switch immediately to it using the option {{code language="none"}}-b{{/code}} of {{code language="none"}}git checkout{{/code}}. 159 159 ))) 160 160 1. ((( 161 - Add the new file [[attach:examples.txt]]:161 +Download and add the new file [[attach:examples.txt]]{{code language="none"}}{{/code}}: 162 162 163 163 {{noformat}} 164 164 $ git add examples.txt ... ... @@ -167,4 +167,159 @@ 167 167 1 files changed, 20 insertions(+), 0 deletions(-) 168 168 create mode 100644 examples.txt 169 169 {{/noformat}} 170 + 171 +Inspecting the commit graph with {{code language="none"}}gitk{{/code}} (or another graphical viewer) you see that the {{code language="none"}}sketches{{/code}} branch now has three commits, while {{code language="none"}}master{{/code}} is still at the second commit. 170 170 ))) 173 +1. ((( 174 +Merging the {{code language="none"}}sketches{{/code}} branch into {{code language="none"}}master{{/code}} means that all changes that have been made in {{code language="none"}}sketches{{/code}} are also applied to {{code language="none"}}master{{/code}}. In order to perform this merge, we have to check out the {{code language="none"}}master{{/code}} branch first: 175 + 176 +{{noformat}} 177 +$ git checkout master 178 +Switched to branch 'master' 179 +$ git merge sketches 180 +Updating 52e2d49..cd63135 181 +Fast-forward 182 + examples.txt | 20 ++++++++++++++++++++ 183 + 1 files changed, 20 insertions(+), 0 deletions(-) 184 + create mode 100644 examples.txt 185 +{{/noformat}} 186 + 187 +This was a //fast-forward// merge: since the {{code language="none"}}master{{/code}} branch was completely contained in the {{code language="none"}}sketches{{/code}} branch, the merge could be done by simply changing the head pointer of {{code language="none"}}master{{/code}} to be the same as the head of {{code language="none"}}sketches{{/code}}. 188 +))) 189 +1. ((( 190 +Now add the line "{{code language="none"}}see some examples in 'examples.txt'{{/code}}" to the file {{code language="none"}}notes.txt{{/code}} and commit this change in the current branch: 191 + 192 +{{noformat}} 193 +$ git add notes.txt 194 +$ git commit -m "added reference to the new examples" 195 +[master a5e244f] added reference to the new examples 196 + 1 files changed, 2 insertions(+), 1 deletions(-) 197 +{{/noformat}} 198 +))) 199 +1. ((( 200 +Switch back to the {{code language="none"}}sketches{{/code}} branch and commit something there. Note that the {{code language="none"}}checkout{{/code}} command modifies your working copy, hence you have to update your text editor's content if you opened one of the files. 201 + 202 +{{noformat}} 203 +$ git checkout sketches 204 +Switched to branch 'sketches' 205 +{{/noformat}} 206 + 207 +Add the line "{{code language="none"}}Move one step left:{{/code}}" and write an updated version of the tape with tape head in the file {{code language="none"}}examples.txt{{/code}}, then commit. 208 + 209 +{{noformat}} 210 +$ git add examples.txt 211 +$ git commit -m "added another example" 212 +[sketches 55a9cb1] added another example 213 + 1 files changed, 5 insertions(+), 0 deletions(-) 214 +{{/noformat}} 215 + 216 +Now our two branches have //diverged//, which means that they cannot be fast-forwarded anymore. 217 +))) 218 +1. ((( 219 +Merge the {{code language="none"}}master{{/code}} branch into {{code language="none"}}sketches{{/code}}: 220 + 221 +{{noformat}} 222 +$ git merge master 223 +Merge made by recursive. 224 + notes.txt | 3 ++- 225 + 1 files changed, 2 insertions(+), 1 deletions(-) 226 +{{/noformat}} 227 + 228 +Using {{code language="none"}}gitk{{/code}} you can see that a new commit was created that has two parent commits. Such a commit is called //merge// commit and is done automatically when a non-fast-forward merge is applied. 229 +))) 230 +1. ((( 231 +Add a commit in each of the two branches using the commands you have already learned. 232 +1. Check out {{code language="none"}}master{{/code}}. 233 +1. ((( 234 +Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}: 235 + 236 +{{noformat nopanel="true"}} 237 + * The finite state machine has an initial state and one or more final states 238 +{{/noformat}} 239 +))) 240 +1. Commit the change to {{code language="none"}}notes.txt{{/code}}. 241 +1. Check out {{code language="none"}}sketches{{/code}} (make sure to refresh your text editor so {{code language="none"}}notes.txt{{/code}} is reset to its previous state, without the change made above). 242 +1. ((( 243 +Insert the following line after line 4 of {{code language="none"}}notes.txt{{/code}}: 244 + 245 +{{noformat nopanel="true"}} 246 + * Each state transition can trigger head movement and data read/write 247 +{{/noformat}} 248 +))) 249 +1. Commit the change to {{code language="none"}}notes.txt{{/code}}. 250 +))) 251 +1. ((( 252 +Merge the {{code language="none"}}master{{/code}} branch into the current branch ({{code language="none"}}sketches{{/code}}): 253 + 254 +{{noformat}} 255 +$ git merge master 256 +Auto-merging notes.txt 257 +CONFLICT (content): Merge conflict in notes.txt 258 +Automatic merge failed; fix conflicts and then commit the result. 259 +{{/noformat}} 260 + 261 +As expected, the branches could not be merged automatically, since both branches modified the same line in the same file. 262 +))) 263 +1. ((( 264 +Use the {{code language="none"}}status{{/code}} command to see the list of affected files: 265 + 266 +{{noformat}} 267 +$ git status 268 +# On branch sketches 269 +# Unmerged paths: 270 +# (use "git add/rm <file>..." as appropriate to mark resolution) 271 +# 272 +# both modified: notes.txt 273 +# 274 +no changes added to commit (use "git add" and/or "git commit -a") 275 +{{/noformat}} 276 +))) 277 +1. ((( 278 +The modified {{code language="none"}}notes.txt{{/code}} should now contain the following text: 279 + 280 +{{noformat nopanel="true"}} 281 +<<<<<<< HEAD 282 + * Each state transition can trigger head movement and data read/write 283 +======= 284 + * The finite state machine has an initial state and one or more final states 285 +>>>>>>> master 286 +{{/noformat}} 287 + 288 +The upper line is the one committed to {{code language="none"}}sketches{{/code}}, while the lower line was committed to {{code language="none"}}master{{/code}}. You have to resolve the conflict by editing the file. In this case the conflict is resolved by keeping both lines in arbitrary order, that means you should just remove the conflict markers (lines 5, 7, and 9 in {{code language="none"}}notes.txt{{/code}}). 289 +))) 290 +1. ((( 291 +Use the {{code language="none"}}add{{/code}} command to mark {{code language="none"}}notes.txt{{/code}} as resolved. Entering {{code language="none"}}git commit{{/code}} without a message will open a text editor with an automatically created commit message. Just close the editor, and the merge commit is completed: 292 + 293 +{{noformat}} 294 +$ git commit 295 +[sketches 21d5ddb] Merge branch 'master' into sketches 296 +$ git show 21d5ddb 297 +commit 21d5ddbbcba4e36464653a2a550dbf595ead921f 298 +Merge: 17f75c7 8af2d50 299 +Author: Miro Spoenemann <msp@informatik.uni-kiel.de> 300 +Date: Tue Oct 16 10:44:09 2012 +0200 301 + 302 + Merge branch 'master' into sketches 303 + 304 + Conflicts: 305 + notes.txt 306 + 307 +diff --cc notes.txt 308 +index 8f72873,bb81298..ba94a08 309 +--- a/notes.txt 310 ++++ b/notes.txt 311 +@@@ -2,6 -2,6 +2,7 @@@ 312 + * Tape head can read or write data 313 + * Tape head can move left or right 314 + * The head is controlled by a finite state machine 315 + + * Each state transition can trigger head movement and data read/write 316 ++ * The finite state machine has an initial state and one or more final states 317 + see some examples in 'examples.txt' 318 +{{/noformat}} 319 +))) 320 + 321 +The {{code language="none"}}gitk{{/code}} tool should now display this graph: 322 + 323 +[[image:attach:turing-graph-01.png]] 324 + 325 +
- Confluence.Code.ConfluencePageClass[0]
-
- Id
-
... ... @@ -1,1 +1,1 @@ 1 -298213 21 +2982134 - URL
-
... ... @@ -1,1 +1,1 @@ 1 -https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/298213 2/Git1 +https://rtsys.informatik.uni-kiel.de/confluence//wiki/spaces/WS12EclPract/pages/2982134/Git