Lecture 4 Branches, Exercises of Data Structures and Algorithms

Creates a new branch called “develop” that points to wherever you ... you're on. B. A. 1. git commit –m “A”. 2. git commit –m “B” master.

Typology: Exercises

2022/2023

Uploaded on 03/01/2023

gwen
gwen 🇺🇸

5

(8)

283 documents

1 / 38

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture 4
Branches
Sign in on the
attendance
sheet!
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26

Partial preview of the text

Download Lecture 4 Branches and more Exercises Data Structures and Algorithms in PDF only on Docsity!

Lecture 4

Branches

Sign in on the attendance sheet!

Last Time

Scenario: You work on two features at once in

a project

b4e2c29: initial commit b5f3729: even more work on feature A 8277e09: even more work on feature B 8b7d883: begin work on feature B 8fc42c6: begin work on feature A 6f96cf3: more work on feature A e167179: more work on feature B master, HEAD

  • Hard to distinguish the two different features that are being worked on based on the git history
  • If the features are related, the commits might interfere with each other

Solution: Non-linear development via

branches

8b7d883: begin work on feature B 8fc42c6: begin work on feature A 6f96cf3: more work on feature A e167179: more work on feature B b4e2c29: initial commit b5f3729: even more work on feature A 8277e09: even more work on feature B master featureA featureB, HEAD

git branch

Example use: git branch develop

  • Creates a new branch called “develop” that points to wherever you are right now (i.e. wherever HEAD is right now)

git checkout

Example use: git checkout develop

  • Switches to the branch named “develop”
  • Instead of a branch name, you can also put a commit hash
  • Very different from “git checkout ” (from last week)! That checkouts a single file, this checkouts the entire branch, including all of its files

Commits are made on whatever branch

you’re on

B A

  1. git commit – m “A”
  2. git commit – m “B” master HEAD

Commits are made on whatever branch

you’re on

B A

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch experiment master HEAD experiment

Commits are made on whatever branch

you’re on

B A C

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch experiment
  4. git checkout experiment
  5. git commit – m “C” master experiment HEAD

Commits are made on whatever branch

you’re on

B A C D

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch experiment
  4. git checkout experiment
  5. git commit – m “C”
  6. git commit – m “D” master experiment HEAD

Commits are made on whatever branch

you’re on

B A C D

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch experiment
  4. git checkout experiment
  5. git commit – m “C”
  6. git commit – m “D”
  7. git branch wildidea
  8. git checkout wildidea master HEAD experiment wildidea

Commits are made on whatever branch

you’re on

B A C D E

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch experiment
  4. git checkout experiment
  5. git commit – m “C”
  6. git commit – m “D”
  7. git branch wildidea
  8. git checkout wildidea
  9. git commit – m “E” master HEAD experiment wildidea

Commits are made on whatever branch

you’re on

B A C D E F

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch experiment
  4. git checkout experiment
  5. git commit – m “C”
  6. git commit – m “D”
  7. git branch wildidea
  8. git checkout wildidea
  9. git commit – m “E”
  10. git checkout master
  11. git commit – m “F” master HEAD experiment wildidea

Exercise: What [directed, acyclic] graph do the following

git commands produce?

  1. git commit – m “A”
  2. git commit – m “B”
  3. git branch stable
  4. git branch experiment
  5. git checkout experiment
  6. git commit – m “C”
  7. git checkout master
  8. git commit – m “D”
  9. git branch goodidea
  10. git checkout experiment
  11. git branch whereami
  12. git commit – m “E”
    1. git checkout goodidea
    2. git checkout master
    3. git commit – m “F”
    4. git checkout whereami
    5. git commit – m “G”
    6. git checkout master B A C D E F stable experiment goodidea master, HEAD G whereami