Skip to content

Commit e09e3bc

Browse files
committed
more detail
1 parent d0bdbb3 commit e09e3bc

1 file changed

Lines changed: 81 additions & 135 deletions

File tree

notes/2025-10-09.md

Lines changed: 81 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,21 @@ We need to write the hash of the second commit to the main file to put that comm
588588

589589
+++{"lesson_part": "main"}
590590

591-
## stash
591+
## Stashing
592+
593+
[git stash](https://git-scm.com/book/en/v2/Git-Tools-Stashing-and-Cleaning)
594+
595+
+++{"lesson_part": "main"}
596+
597+
Imagine you have worked on something part way, but not finished it, so you do not want to make a commit yet, but you need to switch and work on something else.
598+
+++{"lesson_part": "main"}
599+
600+
let's create such a scenario in our github inclass repo
592601
```{code-cell} bash
593602
:tags: ["skip-execution"]
594603
cd ../gh-inclass-fa25-brownsarahm/
595604
```
596605

597-
+++{"lesson_part": "main","type":"output"}
598-
599-
```{code-block} console
600-
```
601606

602607
+++{"lesson_part": "main"}
603608

@@ -615,26 +620,9 @@ Your branch is up to date with 'origin/organization'.
615620
nothing to commit, working tree clean
616621
```
617622

618-
+++{"lesson_part": "main"}
619-
620-
```{code-cell} bash
621-
:tags: ["skip-execution"]
622-
ls
623-
```
624-
625-
+++{"lesson_part": "main","type":"output"}
626-
627-
```{code-block} console
628-
abstract_base_class.py important_classes.py
629-
alternative_classes.py LICENSE.md
630-
API.md README.md
631-
CONTRIBUTING.md scratch.ipynb
632-
docs setup.py
633-
example.md tests
634-
helper_functions.py
635-
```
636623

637624
+++{"lesson_part": "main"}
625+
We will add some new work to the README
638626

639627
```{code-cell} bash
640628
:tags: ["skip-execution"]
@@ -668,6 +656,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
668656
```
669657

670658
+++{"lesson_part": "main"}
659+
If we want to switch branches now,
671660

672661
```{code-cell} bash
673662
:tags: ["skip-execution"]
@@ -682,9 +671,26 @@ error: Your local changes to the following files would be overwritten by checkou
682671
Please commit your changes or stash them before you switch branches.
683672
Aborting
684673
```
674+
we get an error
685675

676+
677+
:::::{important}
678+
this is git protecting you
679+
680+
`git checkout main` would:
681+
- read the `.git/refs/heads/main` file
682+
- read the commit at that hash
683+
- use the tree for that commit and write files reading from the blob objects and to the file names in the tree
684+
- upate the HEAD pointer
685+
686+
this would include writing the `README` with the content as of our last commit on the main branch, and over writing the current version, so we would lose anything that has not been commited.
687+
:::::::
686688
+++{"lesson_part": "main"}
687689

690+
`git stash`
691+
stores temporary changes without making a commit so that we can come back to them.
692+
693+
688694
```{code-cell} bash
689695
:tags: ["skip-execution"]
690696
git stash
@@ -697,6 +703,7 @@ Saved working directory and index state WIP on organization: e899a0e begin reorg
697703
```
698704

699705
+++{"lesson_part": "main"}
706+
we can see what we have stashed:
700707

701708
```{code-cell} bash
702709
:tags: ["skip-execution"]
@@ -710,6 +717,7 @@ stash@{0}: WIP on organization: e899a0e begin reorg
710717
```
711718

712719
+++{"lesson_part": "main"}
720+
now we can switch
713721

714722
```{code-cell} bash
715723
:tags: ["skip-execution"]
@@ -723,24 +731,9 @@ Switched to branch 'main'
723731
Your branch is up to date with 'origin/main'.
724732
```
725733

726-
+++{"lesson_part": "main"}
727-
728-
```{code-cell} bash
729-
:tags: ["skip-execution"]
730-
git sttatus
731-
```
732-
733-
+++{"lesson_part": "main","type":"output"}
734-
735-
```{code-block} console
736-
git: 'sttatus' is not a git command. See 'git --help'.
737-
738-
The most similar command is
739-
status
740-
```
741734

742735
+++{"lesson_part": "main"}
743-
736+
and apply the changes
744737
```{code-cell} bash
745738
:tags: ["skip-execution"]
746739
git stash apply
@@ -765,9 +758,11 @@ Untracked files:
765758
766759
no changes added to commit (use "git add" and/or "git commit -a")
767760
```
761+
we got a merge conflict, but that is okay
768762

769763
+++{"lesson_part": "main"}
770764

765+
we can fix it
771766
```{code-cell} bash
772767
:tags: ["skip-execution"]
773768
nano README.md
@@ -779,65 +774,14 @@ nano README.md
779774
```
780775

781776
+++{"lesson_part": "main"}
782-
783-
```{code-cell} bash
784-
:tags: ["skip-execution"]
785-
git status
786-
```
787-
788-
+++{"lesson_part": "main","type":"output"}
789-
790-
```{code-block} console
791-
On branch main
792-
Your branch is up to date with 'origin/main'.
793-
794-
Unmerged paths:
795-
(use "git restore --staged <file>..." to unstage)
796-
(use "git add <file>..." to mark resolution)
797-
both modified: README.md
798-
799-
Untracked files:
800-
(use "git add <file>..." to include in what will be committed)
801-
.secret
802-
803-
no changes added to commit (use "git add" and/or "git commit -a")
804-
```
805-
777+
then add and commit
806778
+++{"lesson_part": "main"}
807779

808780
```{code-cell} bash
809781
:tags: ["skip-execution"]
810782
git add README.md
811783
```
812784

813-
+++{"lesson_part": "main","type":"output"}
814-
815-
```{code-block} console
816-
```
817-
818-
+++{"lesson_part": "main"}
819-
820-
```{code-cell} bash
821-
:tags: ["skip-execution"]
822-
git status
823-
```
824-
825-
+++{"lesson_part": "main","type":"output"}
826-
827-
```{code-block} console
828-
On branch main
829-
Your branch is up to date with 'origin/main'.
830-
831-
Changes to be committed:
832-
(use "git restore --staged <file>..." to unstage)
833-
modified: README.md
834-
835-
Untracked files:
836-
(use "git add <file>..." to include in what will be committed)
837-
.secret
838-
839-
```
840-
841785
+++{"lesson_part": "main"}
842786

843787
```{code-cell} bash
@@ -873,55 +817,17 @@ Untracked files:
873817
nothing added to commit but untracked files present (use "git add" to track)
874818
```
875819

876-
+++{"lesson_part": "main"}
877820

878-
```{code-cell} bash
879-
:tags: ["skip-execution"]
880-
git blame
881-
```
821+
+++{"lesson_part": "main","type":"heading"}
882822

883-
+++{"lesson_part": "main","type":"output"}
823+
## Git can help with Debugging
824+
825+
[chapter](https://git-scm.com/book/en/v2/Git-Tools-Debugging-with-Git)
884826

885-
```{code-block} console
886-
usage: git blame [<options>] [<rev-opts>] [<rev>] [--] <file>
887-
888-
<rev-opts> are documented in git-rev-list(1)
889-
890-
--[no-]incremental show blame entries as we find them, incrementally
891-
-b do not show object names of boundary commits (Default: off)
892-
--[no-]root do not treat root commits as boundaries (Default: off)
893-
--[no-]show-stats show work cost statistics
894-
--[no-]progress force progress reporting
895-
--[no-]score-debug show output score for blame entries
896-
-f, --[no-]show-name show original filename (Default: auto)
897-
-n, --[no-]show-number
898-
show original linenumber (Default: off)
899-
-p, --[no-]porcelain show in a format designed for machine consumption
900-
--[no-]line-porcelain show porcelain format with per-line commit information
901-
-c use the same output mode as git-annotate (Default: off)
902-
-t show raw timestamp (Default: off)
903-
-l show long commit SHA1 (Default: off)
904-
-s suppress author name and timestamp (Default: off)
905-
-e, --[no-]show-email show author email instead of name (Default: off)
906-
-w ignore whitespace differences
907-
--[no-]ignore-rev <rev>
908-
ignore <rev> when blaming
909-
--[no-]ignore-revs-file <file>
910-
ignore revisions from <file>
911-
--[no-]color-lines color redundant metadata from previous line differently
912-
--[no-]color-by-age color lines by age
913-
--[no-]minimal spend extra cycles to find better match
914-
-S <file> use revisions from <file> instead of calling git-rev-list
915-
--[no-]contents <file>
916-
use <file>'s contents as the final image
917-
-C[<score>] find line copies within and across files
918-
-M[<score>] find line movements within and across files
919-
-L <range> process only line range <start>,<end> or function :<funcname>
920-
--[no-]abbrev[=<n>] use <n> digits to display object names
921827

922-
```
923828

924829
+++{"lesson_part": "main"}
830+
blame tells us who and when each line of a file was last changed.
925831

926832
```{code-cell} bash
927833
:tags: ["skip-execution"]
@@ -946,6 +852,38 @@ ff9fb6ce (Sarah M Brown 2025-10-09 13:24:28 -0400 12) > | LICENSE.md | the info
946852
ff9fb6ce (Sarah M Brown 2025-10-09 13:24:28 -0400 13) > | CONTRIBUTING.md | instructions for how people can contribute to the project|
947853
```
948854

855+
we can also view this with annotation and visually in GitHub
856+
857+
858+
git will help you do a binary search to find what commit introduced a bug.
859+
860+
+++{"lesson_part": "main"}
861+
we have to tell it to start, then tell it that the current commit is bad, then tell it the last good commit (or a reference to it)
862+
863+
```
864+
git bisect start
865+
git bisect bad
866+
git biset good <ref>
867+
```
868+
869+
870+
871+
872+
To do this we need to have to tell it what commit was good, this is one of the reasons that using tags can be helpful
873+
874+
875+
+++{"lesson_part": "main"}
876+
877+
there are multiple ways to refer to a point in the history
878+
879+
[revision selection](https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection)
880+
881+
882+
883+
+++{"lesson_part": "main"}
884+
First let's choose a point to use as our last good commit by scanning the previous commits.
885+
886+
949887
+++{"lesson_part": "main"}
950888

951889
```{code-cell} bash
@@ -985,7 +923,7 @@ Date: Thu Sep 11 14:49:01 2025 +0000
985923
```
986924

987925
+++{"lesson_part": "main"}
988-
926+
We will start `git bisect` first, this is our search for the "bad commit"
989927
```{code-cell} bash
990928
:tags: ["skip-execution"]
991929
git bisect start
@@ -999,6 +937,7 @@ status: waiting for both good and bad commits
999937

1000938
+++{"lesson_part": "main"}
1001939

940+
Now, lets tell it that the current commit is bad, this reprsents that we just rcevied the bug report.
1002941
```{code-cell} bash
1003942
:tags: ["skip-execution"]
1004943
git bisect bad
@@ -1010,7 +949,12 @@ git bisect bad
1010949
status: waiting for good commit(s), bad commit known
1011950
```
1012951

952+
953+
now we get the updated status
954+
1013955
+++{"lesson_part": "main"}
956+
next we tell it what was the last known, not necessarily the last, good commit. We'll use the about branch commit. This would represent a case where maybe we switched to to that branch locally, ran a test for the the new bug and it passed.
957+
1014958

1015959
```{code-cell} bash
1016960
:tags: ["skip-execution"]
@@ -1026,6 +970,8 @@ Bisecting: 0 revisions left to test after this (roughly 1 step)
1026970

1027971
+++{"lesson_part": "main"}
1028972

973+
Then we check each commit it checkout for us and label it as good or bad by seeing if the budg exists there.
974+
1029975
```{code-cell} bash
1030976
:tags: ["skip-execution"]
1031977
git bisect bad

0 commit comments

Comments
 (0)