You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
592
601
```{code-cell} bash
593
602
:tags: ["skip-execution"]
594
603
cd ../gh-inclass-fa25-brownsarahm/
595
604
```
596
605
597
-
+++{"lesson_part": "main","type":"output"}
598
-
599
-
```{code-block} console
600
-
```
601
606
602
607
+++{"lesson_part": "main"}
603
608
@@ -615,26 +620,9 @@ Your branch is up to date with 'origin/organization'.
615
620
nothing to commit, working tree clean
616
621
```
617
622
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
-
```
636
623
637
624
+++{"lesson_part": "main"}
625
+
We will add some new work to the README
638
626
639
627
```{code-cell} bash
640
628
:tags: ["skip-execution"]
@@ -668,6 +656,7 @@ no changes added to commit (use "git add" and/or "git commit -a")
668
656
```
669
657
670
658
+++{"lesson_part": "main"}
659
+
If we want to switch branches now,
671
660
672
661
```{code-cell} bash
673
662
:tags: ["skip-execution"]
@@ -682,9 +671,26 @@ error: Your local changes to the following files would be overwritten by checkou
682
671
Please commit your changes or stash them before you switch branches.
683
672
Aborting
684
673
```
674
+
we get an error
685
675
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
+
:::::::
686
688
+++{"lesson_part": "main"}
687
689
690
+
`git stash`
691
+
stores temporary changes without making a commit so that we can come back to them.
692
+
693
+
688
694
```{code-cell} bash
689
695
:tags: ["skip-execution"]
690
696
git stash
@@ -697,6 +703,7 @@ Saved working directory and index state WIP on organization: e899a0e begin reorg
697
703
```
698
704
699
705
+++{"lesson_part": "main"}
706
+
we can see what we have stashed:
700
707
701
708
```{code-cell} bash
702
709
:tags: ["skip-execution"]
@@ -710,6 +717,7 @@ stash@{0}: WIP on organization: e899a0e begin reorg
710
717
```
711
718
712
719
+++{"lesson_part": "main"}
720
+
now we can switch
713
721
714
722
```{code-cell} bash
715
723
:tags: ["skip-execution"]
@@ -723,24 +731,9 @@ Switched to branch 'main'
723
731
Your branch is up to date with 'origin/main'.
724
732
```
725
733
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
-
```
741
734
742
735
+++{"lesson_part": "main"}
743
-
736
+
and apply the changes
744
737
```{code-cell} bash
745
738
:tags: ["skip-execution"]
746
739
git stash apply
@@ -765,9 +758,11 @@ Untracked files:
765
758
766
759
no changes added to commit (use "git add" and/or "git commit -a")
767
760
```
761
+
we got a merge conflict, but that is okay
768
762
769
763
+++{"lesson_part": "main"}
770
764
765
+
we can fix it
771
766
```{code-cell} bash
772
767
:tags: ["skip-execution"]
773
768
nano README.md
@@ -779,65 +774,14 @@ nano README.md
779
774
```
780
775
781
776
+++{"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
806
778
+++{"lesson_part": "main"}
807
779
808
780
```{code-cell} bash
809
781
:tags: ["skip-execution"]
810
782
git add README.md
811
783
```
812
784
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
-
841
785
+++{"lesson_part": "main"}
842
786
843
787
```{code-cell} bash
@@ -873,55 +817,17 @@ Untracked files:
873
817
nothing added to commit but untracked files present (use "git add" to track)
We will start `git bisect` first, this is our search for the "bad commit"
989
927
```{code-cell} bash
990
928
:tags: ["skip-execution"]
991
929
git bisect start
@@ -999,6 +937,7 @@ status: waiting for both good and bad commits
999
937
1000
938
+++{"lesson_part": "main"}
1001
939
940
+
Now, lets tell it that the current commit is bad, this reprsents that we just rcevied the bug report.
1002
941
```{code-cell} bash
1003
942
:tags: ["skip-execution"]
1004
943
git bisect bad
@@ -1010,7 +949,12 @@ git bisect bad
1010
949
status: waiting for good commit(s), bad commit known
1011
950
```
1012
951
952
+
953
+
now we get the updated status
954
+
1013
955
+++{"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
+
1014
958
1015
959
```{code-cell} bash
1016
960
:tags: ["skip-execution"]
@@ -1026,6 +970,8 @@ Bisecting: 0 revisions left to test after this (roughly 1 step)
1026
970
1027
971
+++{"lesson_part": "main"}
1028
972
973
+
Then we check each commit it checkout for us and label it as good or bad by seeing if the budg exists there.
0 commit comments