blob: 2509439c359a91c526c943f325c6f6885781bcc3 [file] [log] [blame]
Resetting Branches
------------------
[graphviz]
----
digraph {
node [style=bold, shape=circle, color="#385d8a", fontname=arial, fontsize=18]
edge [style=bold, color="#385d8a", arrowhead=none]
D -> C -> B -> A
edge [arrowhead=normal]
node [shape=box, style=filled, fillcolor=lightgrey, color=black]
HEAD [fillcolor="#555555", fontcolor=white]
HEAD -> master -> D
{ rank=same; HEAD; master; D }
}
----
Branch can also be moved "manually"
[role="incremental"]
--
* 'Q:' what happens when we reset branch `master` to commit `B`
+
----
git reset B
----
--
Resetting Branches
------------------
[graphviz]
----
digraph {
node [style=bold, shape=circle, color="#385d8a", fontname=arial, fontsize=18]
edge [style=bold, color="#385d8a", arrowhead=none]
D -> C -> B -> A
edge [arrowhead=normal]
node [shape=box, style=filled, fillcolor=lightgrey, color=black]
HEAD [fillcolor="#555555", fontcolor=white]
master [color=red, fontcolor=red]
HEAD -> master -> B [color=red]
{ rank=same; HEAD; master; B }
master_old [style=dashed, label=master, color=grey, fontcolor=grey]
master_old -> D [style=dashed, color=grey]
{ rank=same; master_old; D }
}
----
Branch now points to commit `B`
[role="incremental"]
* 'Q:' what happens to the 'working tree' and 'index' on branch reset?
** 'soft', 'mixed' and 'hard' reset
Resetting Branches - Soft, Mixed and Hard
-----------------------------------------
[grid="rows", format="csv"]
[options="header"]
|==============================
Reset,working tree,index,branch
soft,[green]#No#,[green]#No#,*Yes*
mixed,[green]#No#,*Yes*,*Yes*
hard,[red]#Yes#,*Yes*,*Yes*
|==============================
Branches - Next Commit After Reset
----------------------------------
[graphviz]
----
digraph {
node [style=bold, shape=circle, color="#385d8a", fontname=arial, fontsize=18]
edge [style=bold, color="#385d8a", arrowhead=none]
D -> C -> B -> A
E [style=filled, color=red, fillcolor=coral1]
E -> B [weight=0, color=red]
edge [arrowhead=normal]
node [shape=box, style=filled, fillcolor=lightgrey, color=black]
master [color=red, fontcolor=red]
master [label=master, color=red, fontcolor=red]
HEAD [fillcolor="#555555", fontcolor=white]
HEAD -> master -> E [color=red, weight=0]
{ rank=same; HEAD; master; E; C}
master_old [style=dashed, label=master, color=grey, fontcolor=grey]
master_old -> B [style=dashed, color=grey]
{ rank=same; master_old; B }
}
----
Commit after reset
* new commit `E`, a successor of `B`, gets created
* `C` and `D` continue to exist but they are not in the history of the master
branch