From 9257068aa30c460b62de055c895f642986650588 Mon Sep 17 00:00:00 2001 From: Sarah M Brown Date: Thu, 19 Sep 2024 20:41:35 -0400 Subject: [PATCH] activities and notes --- _practice/2024-09-19.md | 10 + _prepare/2024-09-24.md | 2 + _review/2024-09-19.md | 2 + activities/practice.md | 7 + activities/prepare.md | 8 + activities/review.md | 7 + notes/2024-09-19.md | 913 +++++++++++++++++++++++++++++++++------- 7 files changed, 789 insertions(+), 160 deletions(-) create mode 100644 _practice/2024-09-19.md create mode 100644 _prepare/2024-09-24.md create mode 100644 _review/2024-09-19.md diff --git a/_practice/2024-09-19.md b/_practice/2024-09-19.md new file mode 100644 index 0000000..6695822 --- /dev/null +++ b/_practice/2024-09-19.md @@ -0,0 +1,10 @@ +1. Update your KWL chart with any learned items. +2. Get set up so that you can contribute to the course website repo from your local system. Note: you can pull from the `compsys-progtools/fall2024` repo, but you do not not have push permission, so there is more to do than clone. Append the commands used and the contents of your `fll2024/.git/config`to a {index}`git-remote-practice.md`. Then, using a text editor (or IDE), wrap each log with three backticks to make them [fenced code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks) and add headings to the sections. +3. [learn about options for how git can display commit history](https://git-scm.com/book/en/v2/Git-Basics-Viewing-the-Commit-History). Try out a few different options. Choose two, write them both to a file (from the command line, not copy&paste), {index}`gitlog-compare.md`. Then, using a text editor (or IDE), wrap each log with three backticks to make them [fenced code blocks](https://www.markdownguide.org/extended-syntax/#fenced-code-blocks) and then add text to the file describing a use case where that format in particular would be helpful. +4. + + Hint for working offline + +Read about [forks](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/about-forks) and working with + [remotes](https://docs.github.com/en/get-started/getting-started-with-git/managing-remote-repositories#adding-a-remote-repository). + \ No newline at end of file diff --git a/_prepare/2024-09-24.md b/_prepare/2024-09-24.md new file mode 100644 index 0000000..dd543a7 --- /dev/null +++ b/_prepare/2024-09-24.md @@ -0,0 +1,2 @@ +1. Bring git questions or scenarios you want to be able to solve to class on Thursday (in your mind or comment here if that helps you remember) +2. Try read and understand the workflow files in your KWL repo, the goal is not to be sure you understand *every* step, but to get an idea about the big picture ideas and just enough to complete the following. Try to modify files, on a prepare branch, so that your name is already filled in and `VioletVex` is already requested as a reviewer when your experience badge (inclass) action runs. We will give the answer in class, but especially **do not do this step on the main branch** it could break your action. Hints: Look for bash commands that we have seen before and `cp` copies a file. \ No newline at end of file diff --git a/_review/2024-09-19.md b/_review/2024-09-19.md new file mode 100644 index 0000000..6e49229 --- /dev/null +++ b/_review/2024-09-19.md @@ -0,0 +1,2 @@ +1. Update your KWL chart with the new items and any learned items. +2. Clone the course website. Append the commands used and the contents of your `fall2024/.git/config`to a {index}`terminal_review.md` (hint: history outputs recent commands and redirects can work with any command, not only echo). Edit the README.md, commit, and try to push the changes. Describe what the error means and which [GitHub Collaboration Feature](https://docs.github.com/en#:~:text=Collaborative%20coding,GitHub%20Copilothttps://docs.github.com/en#:~:text=Collaborative%20coding,GitHub%20Copilot) you think would enable you to push? (answer in the `terminal_review.md`) \ No newline at end of file diff --git a/activities/practice.md b/activities/practice.md index b91869c..01fe5be 100644 --- a/activities/practice.md +++ b/activities/practice.md @@ -37,4 +37,11 @@ Activities: Activities: ```{include} ../_practice/2024-09-17.md +``` +## 2024-09-19 + +[related notes](../notes/2024-09-19) + +Activities: +```{include} ../_practice/2024-09-19.md ``` \ No newline at end of file diff --git a/activities/prepare.md b/activities/prepare.md index b8164d7..2953dfb 100644 --- a/activities/prepare.md +++ b/activities/prepare.md @@ -31,10 +31,18 @@ Activities: Activities: ```{include} ../_prepare/2024-09-17.md ``` +(prepare2024-09-19)= ## 2024-09-19 [related notes](../notes/2024-09-19) Activities: ```{include} ../_prepare/2024-09-19.md +``` +## 2024-09-24 + +[related notes](../notes/2024-09-24) + +Activities: +```{include} ../_prepare/2024-09-24.md ``` \ No newline at end of file diff --git a/activities/review.md b/activities/review.md index 578e0f6..c493b91 100644 --- a/activities/review.md +++ b/activities/review.md @@ -35,4 +35,11 @@ Activities: Activities: ```{include} ../_review/2024-09-17.md +``` +## 2024-09-19 + +[related notes](../notes/2024-09-19) + +Activities: +```{include} ../_review/2024-09-19.md ``` \ No newline at end of file diff --git a/notes/2024-09-19.md b/notes/2024-09-19.md index 330ae8a..d136f9d 100644 --- a/notes/2024-09-19.md +++ b/notes/2024-09-19.md @@ -1,35 +1,97 @@ -brownsarahm@gh-inclass-brownsarahm $ cd .. -brownsarahm@systems $ clear +--- +file_format: mystnb +kernelspec: + name: python3 +--- ++++{"lesson_part":"main"} +# When do I get an advantage from git and bash? ++++{"lesson_part":"main"} +so far we have used git and bash to accomplish familiar goals, and git and bash feel like just extra work for familiar goals. ++++{"lesson_part":"main"} +Today, we will start to see why git and bash are essential skills: they give you efficiency gains and time traveling super powers (within your work, only, sorry) ++++{"lesson_part":"site"} +## Setting the stage +To [prepare for today's class](prep2024-09-19) you examined an open source project. +We noticed that while the contents inside and the distribution of languages used as well +as the specific code, or the *content* of the files was all different, a lot of the +*organization* was similar. +Most had certain [community health files](https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/creating-a-default-community-health-file) and basic info files: +- `CONTRIBUTING` +- `CODE_OF_CONDUCT` +- `README.MD` +- `LICENSE` +- `GOVERNANCE.MD` +## Important references +Use these for checking facts and resources. +- [bash](https://www.gnu.org/software/bash/manual/html_node/index.html) +- [git](https://git-scm.com/docs) ++++{"lesson_part":"main"} +## Setup +First, we'll go back to our github inclass folder, locally ++++{"lesson_part": "main"} +```{code-cell} bash +:tags: ["skip-execution"] +cd gh-inclass-brownsarahm/ +``` ++++{"lesson_part": "main"} +And confirm we are where we want to be +```{code-cell} bash +:tags: ["skip-execution"] +pwd +``` ++++{"lesson_part": "main","type":"output"} -brownsarahm@systems $ cd gh-inclass-brownsarahm/ -brownsarahm@gh-inclass-brownsarahm $ pwd +```{code-block} console /Users/brownsarahm/Documents/inclass/systems/gh-inclass-brownsarahm -brownsarahm@gh-inclass-brownsarahm $ gh repo view --web -Opening github.com/compsys-progtools/gh-inclass-brownsarahm in your browser. -brownsarahm@gh-inclass-brownsarahm $ git pull +``` ++++{"lesson_part":"site"} + +Next get the files for today's activity: +1. Find your PR that I opened for you today that has the title, "9/19 in class activity" +2. Mark it ready for review to change from draft +3. Merge it + +```{note} +in the issue PR it has the info about draft PRs in a link +``` + + + ++++{"lesson_part": "main"} + +Now we pull to get the files locally: + +```{code-cell} bash +:tags: ["skip-execution"] +git pull +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console remote: Enumerating objects: 20, done. remote: Counting objects: 100% (20/20), done. remote: Compressing objects: 100% (9/9), done. @@ -39,58 +101,194 @@ From https://github.com/compsys-progtools/gh-inclass-brownsarahm 0c12714..991ee65 main -> origin/main * [new branch] organizing_ac -> origin/organizing_ac Already up to date. -brownsarahm@gh-inclass-brownsarahm $ git status +``` +Note how many things it got + ++++{"lesson_part": "main"} + +and check out status +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch fun_fact Your branch is up to date with 'origin/fun_fact'. nothing to commit, working tree clean -brownsarahm@gh-inclass-brownsarahm $ ls .git +``` + +we are still on fun_fact ++++{"lesson_part": "main"} + +## How does git store information? + +In class, I received the following question +> Why are we on the `fun_fact` branch, not `main`? + +This is because of how a `branch` is implemented and how git runs. + +Instead of storing important things in *variables* that only have scope of how long the program is **active** git stores its imporant information in *files* that it reads each time we run a command. +All of git's data is in the `.git` directory. + ++++{"lesson_part": "main"} +```{code-cell} bash +:tags: ["skip-execution"] +ls .git +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console COMMIT_EDITMSG ORIG_HEAD description info packed-refs FETCH_HEAD REBASE_HEAD hooks logs refs HEAD config index objects -brownsarahm@gh-inclass-brownsarahm $ cat .git/HEAD +``` + +We will learn more about these files later, but looking at one helps us answer the question + ++++{"lesson_part": "main"} + +First we will look at the `HEAD` file + +```{code-cell} bash +:tags: ["skip-execution"] +cat .git/HEAD +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console ref: refs/heads/fun_fact -brownsarahm@gh-inclass-brownsarahm $ git checkout main +``` + + ++++{"lesson_part": "main"} + +`HEAD` is a pointer to the currently checked out branch. + +The other files with `HEAD` in their name are similarly pointers to other references, named corresponding to other things. + + + ++++{"lesson_part": "main"} + +Next we switch to main, since we want to be there for the files we merged anyway + +```{code-cell} bash +:tags: ["skip-execution"] +git checkout main +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console Switched to branch 'main' Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded. (use "git pull" to update your local branch) -brownsarahm@gh-inclass-brownsarahm $ cat .git/HEAD +``` + ++++{"lesson_part": "main"} + +Now we can look at the `HEAD` file again +```{code-cell} bash +:tags: ["skip-execution"] +cat .git/HEAD +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console ref: refs/heads/main -brownsarahm@gh-inclass-brownsarahm $ cat .git/refs/heads/main +``` +it changed! because one the the things that `git checkout` does is update the head pointer. + ++++{"lesson_part": "main"} + +So `HEAD` is a pointer to the branch, but the branch is also a pointer to a commit +```{code-cell} bash +:tags: ["skip-execution"] +cat .git/refs/heads/main +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console 0c1271483e62e69b8b3fc329203617b7093413df -brownsarahm@gh-inclass-brownsarahm $ git log +``` +that file has only the hash of a commit + +Each of us will have a unique hash, we'll learn more about why for next week ++++{"lesson_part": "main"} + +but if we use `git log` +```{code-cell} bash +:tags: ["skip-execution"] +git log +``` + +```{important} +`git log` starts a program that you can exit with the {kbd}`q` key. +``` + ++++{"lesson_part": "main","type":"output"} + +The branch pointer matches the lastcommit where the HEAD and main pointers are. (`git log` also reads those files...) +```{code-block} console commit 0c1271483e62e69b8b3fc329203617b7093413df (HEAD -> main, my_branch_checkedoutb, my_branch) Merge: 0e7c990 c7375fa Author: Sarah Brown Date: Tue Sep 17 12:50:51 2024 -0400 +``` - Merge pull request #4 from compsys-progtools/1-create-a-readme - - create readme closes #1 - -commit c7375faca0043cf3c233d705201851a10e4e53ac (origin/1-create-a-readme, 1-create-a-readme) -Author: Sarah M Brown -Date: Thu Sep 12 13:42:56 2024 -0400 +```{note} +This is truncated output for brevity +``` ++++{"lesson_part": "main"} - create readme closes #1 +Now again, we can use git status -commit 0e7c990886ec282ba570b3400908ff46698e7dc0 -Author: Sarah Brown -Date: Thu Sep 12 13:21:42 2024 -0400 +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` - start about file closes #3 ++++{"lesson_part": "main","type":"output"} -commit 03733421ad69f816094fa62e3031a7703aa308e3 -Author: Sarah Brown -brownsarahm@gh-inclass-brownsarahm $ git status +```{code-block} console On branch main Your branch is behind 'origin/main' by 2 commits, and can be fast-forwarded. (use "git pull" to update your local branch) nothing to commit, working tree clean -brownsarahm@gh-inclass-brownsarahm $ ls +``` + ++++{"lesson_part": "main"} +We're behind, so the files we merged into main are not here yet +```{code-cell} bash +:tags: ["skip-execution"] +ls +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console README.md about.md -brownsarahm@gh-inclass-brownsarahm $ git pull +``` + ++++{"lesson_part": "main"} +so, we will pull +```{code-cell} bash +:tags: ["skip-execution"] +git pull +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console Updating 0c12714..991ee65 Fast-forward API.md | 1 + @@ -128,117 +326,240 @@ Fast-forward create mode 100644 tests_helpers.py create mode 100644 tests_imp.py create mode 100644 tsets_abc.py -brownsarahm@gh-inclass-brownsarahm $ cat API.md -jupyterbook file to generate api documentation brownsarahm@gh-inclass-brownsarahm $ cat README.md -# GitHub Practice +``` -Name: Sarah Brown -brownsarahm@gh-inclass-brownsarahm $ cat API.md -jupyterbook file to generate api documentation brownsarahm@gh-inclass-brownsarahm $ -brownsarahm@gh-inclass-brownsarahm $ -brownsarahm@gh-inclass-brownsarahm $ cat API.md -jupyterbook file to generate api documentation brownsarahm@gh-inclass-brownsarahm $ -brownsarahm@gh-inclass-brownsarahm $ cat API.md -jupyterbook file to generate api documentation brownsarahm@gh-inclass-brownsarahm $ cat README.md + ++++{"lesson_part":"main"} + +## Organizing a project (working with files) + +A common question is about how to organize projects. While our main focus +in this class session is the `bash` commands to do it, the _task_ that we are +going to do is to organize a hypothetical python project + + +Put another way, we are using organizing a project as the *context* to motivate practicing with +bash commands for moving files. + + +A different way to learn this might be to through a slide deck that lists commands and describes what each one does and then have examples at the end. Instead, we are going to focus on organizing files, and I will introduce the commands we need along the ways. + ++++{"lesson_part":"main"} + +next we are going to pretend we worked on the project and made a bunch of files + +I gave a bunch of files, each with a short phrase in them. + +- none of these are functional files +- the phrases mean you can inspect them on the terminal + ++++{"lesson_part":"site"} + +```{note} +file extensions are for people; they do not specify what the file is actually written like +``` ++++{"lesson_part":"main"} + +these are all *actually* plain text files ++++{"lesson_part": "main"} + +For example +```{code-cell} bash +:tags: ["skip-execution"] +cat API.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console +jupyterbook file to generate api documentation +``` + ++++{"lesson_part": "main"} +But our older files are as expected +```{code-cell} bash +:tags: ["skip-execution"] +cat README.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console # GitHub Practice Name: Sarah Brown -brownsarahm@gh-inclass-brownsarahm $ cat --help +``` + ++++{"lesson_part": "main"} +```{note} +Here we talked about how those small files do not have a new line +character at the end +``` + +```{note} +On Windows, students ge the warning about {term}`CRLF` and {term}`LF` + +There is [setting in git](https://git-scm.com/docs/gitfaq#:~:text=With%20text%20files,in%20some%20projects%3A) that controls it. For a good explanation, consider this [stack overflow question](https://stackoverflow.com/questions/1967370/git-replacing-lf-with-crlf#:~:text=is%20also%20possible).-,How%20autocrlf%20works%3A,-core.autocrlf%3Dtrue) about how it works. + +[GitHub](https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings) also has a whole file on how to work with this. + +[Wikipedia's history in the Newline article](https://en.wikipedia.org/wiki/Newline#History) notes that the CRLF that Windows uses actually comes from the era of teletype machines. +Unix adopted LF alone and Apple (pre OsX) used CR alone. + +[more OSs are described in a table](https://en.wikipedia.org/wiki/Newline#History:~:text=Software%20applications%20and%20operating%20system%20representation%20of%20a%20newline%20with%20one%20or%20two%20control%20characters) +``` + + + ++++{"lesson_part": "main"} +### How does `cat` work? +```{code-cell} bash +:tags: ["skip-execution"] +cat --help +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console cat: illegal option -- - usage: cat [-belnstuv] [file ...] -brownsarahm@gh-inclass-brownsarahm $ cat +``` +it doesn't have a help option, but the error still gives us the beginning +of its documentation. it says there are options we can provide `[-belnstuv]` +and then we pass it a file `[file...]` + ++++{"lesson_part": "main"} + +If we run it without an explicit file, it uses [STDIN](https://man7.org/linux/man-pages/man1/cat.1.html#:~:text=Concatenate%20FILE(s)%20to%20standard%20output.%0A%0A%20%20%20%20%20%20%20With%20no%20FILE%2C%20or%20when%20FILE%20is%20%2D%2C%20read%20standard%20input.) which we can see by trying it, or from its docs +```{code-cell} bash +:tags: ["skip-execution"] +cat +``` + ++++{"lesson_part": "main","type":"output"} +each time we type things into STDIN, it outputs that +```{code-block} console lksdfldkfds lksdfldkfds ^C -brownsarahm@gh-inclass-brownsarahm $ git branch -r - origin/1-create-a-readme - origin/HEAD -> origin/main - origin/fun_fact - origin/main - origin/organizing_ac -brownsarahm@gh-inclass-brownsarahm $ git checkout -b organization -Switched to a new branch 'organization' -brownsarahm@gh-inclass-brownsarahm $ git log -commit 991ee65fa0d0692bd097915daec156aa95eba82f (HEAD -> organization, origin/main, origin/HEAD, main) -Merge: 0c12714 1ee9c9f -Author: Sarah Brown -Date: Thu Sep 19 12:53:29 2024 -0400 +``` - Merge pull request #5 from compsys-progtools/organizing_ac - - Sept 19 in class activity +we can ust {kbd}`CTRL` + {kbd}`C` (`^C` means that is what I pressed) +to exit. -commit 1ee9c9f09bd970d3e328f663b78f5fe9c98da2dc (origin/organizing_ac) -Author: Sarah M Brown -Date: Thu Sep 19 12:16:49 2024 -0400 - add files for organizing activity ++++{"lesson_part": "main"} +## Files, Redirects, git restore -commit 0c1271483e62e69b8b3fc329203617b7093413df (my_branch_checkedoutb, my_branch) -Merge: 0e7c990 c7375fa -Author: Sarah Brown -Date: Tue Sep 17 12:50:51 2024 -0400 - Merge pull request #4 from compsys-progtools/1-create-a-readme - - create readme closes #1 -brownsarahm@gh-inclass-brownsarahm $ git status +we will work on a branch so that we can easily recover from any mistakes +```{code-cell} bash +:tags: ["skip-execution"] +git checkout -b organization +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console +Switched to a new branch 'organization' +``` + ++++{"lesson_part": "main"} +and check status to ensure we are where we want to be and note that no files have been changed +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch organization nothing to commit, working tree clean -brownsarahm@gh-inclass-brownsarahm $ cat README.md +``` + ++++{"lesson_part": "main"} +Let's review what is in the README + +```{code-cell} bash +:tags: ["skip-execution"] +cat README.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console # GitHub Practice Name: Sarah Brown -brownsarahm@gh-inclass-brownsarahm $ echo "its finally fall" +``` + ++++{"lesson_part": "main"} +Echo repeats things we pass into it + +```{code-cell} bash +:tags: ["skip-execution"] +echo "its finally fall" +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console its finally fall -brownsarahm@gh-inclass-brownsarahm $ git log -commit 991ee65fa0d0692bd097915daec156aa95eba82f (HEAD -> organization, origin/main, origin/HEAD, main) -Merge: 0c12714 1ee9c9f -Author: Sarah Brown -Date: Thu Sep 19 12:53:29 2024 -0400 +``` - Merge pull request #5 from compsys-progtools/organizing_ac - - Sept 19 in class activity -commit 1ee9c9f09bd970d3e328f663b78f5fe9c98da2dc (origin/organizing_ac) -Author: Sarah M Brown -Date: Thu Sep 19 12:16:49 2024 -0400 - add files for organizing activity ++++{"lesson_part": "main"} -commit 0c1271483e62e69b8b3fc329203617b7093413df (my_branch_checkedoutb, my_branch) -Merge: 0e7c990 c7375fa -Author: Sarah Brown -Date: Tue Sep 17 12:50:51 2024 -0400 +since the `echo` program writes to the STDOUT file, we can change it to write to another +file by {term}`redirect`ing it to another file. - Merge pull request #4 from compsys-progtools/1-create-a-readme - - create readme closes #1 +```{code-cell} bash +:tags: ["skip-execution"] +echo "its finally fall" > README.md +``` -commit c7375faca0043cf3c233d705201851a10e4e53ac (origin/1-create-a-readme, 1-create-a-readme) -Author: Sarah M Brown -Date: Thu Sep 12 13:42:56 2024 -0400 ++++{"lesson_part": "main","type":"output"} - create readme closes #1 +```{code-block} console +``` -commit 0e7c990886ec282ba570b3400908ff46698e7dc0 -Author: Sarah Brown -Date: Thu Sep 12 13:21:42 2024 -0400 +There is no outut of this command - start about file closes #3 ++++{"lesson_part": "main"} +but we can look at the file -commit 03733421ad69f816094fa62e3031a7703aa308e3 -Author: Sarah Brown -Date: Thu Sep 12 12:57:58 2024 -0400 +```{code-cell} bash +:tags: ["skip-execution"] +cat README.md +``` - Initial commit -brownsarahm@gh-inclass-brownsarahm $ echo "its finally fall" -its finally fall -brownsarahm@gh-inclass-brownsarahm $ echo "its finally fall" > README.md -brownsarahm@gh-inclass-brownsarahm $ cat README.md ++++{"lesson_part": "main","type":"output"} + +```{code-block} console its finally fall -brownsarahm@gh-inclass-brownsarahm $ git status +``` ++++{"lesson_part":"main"} + + +It wrote over. This would be bad, we lost content, but this is what git is for! + +It is *very very* easy to undo work since our last commit. + +This is good for times when you have something you have an idea and you do not know if it is going to work, so you make a commit before you try it. Then you can try it out. If it doesn't work you can undo and go back to the place where you made the commit. + ++++{"lesson_part": "main"} + +As always we start by checking in +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch organization Changes not staged for commit: (use "git add ..." to update what will be committed) @@ -246,22 +567,140 @@ Changes not staged for commit: modified: README.md no changes added to commit (use "git add" and/or "git commit -a") -brownsarahm@gh-inclass-brownsarahm $ git restore README.md -brownsarahm@gh-inclass-brownsarahm $ git status +``` + +it gives us a reminder, `use "git restore ..." to discard changes in working directory` + ++++{"lesson_part": "main"} + +So we do that: +```{code-cell} bash +:tags: ["skip-execution"] +git restore README.md +``` + + ++++{"lesson_part": "main"} + +then check in with git again +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch organization nothing to commit, working tree clean -brownsarahm@gh-inclass-brownsarahm $ cat README.md +``` + ++++{"lesson_part": "main"} +and check the file +```{code-cell} bash +:tags: ["skip-execution"] +cat README.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console # GitHub Practice Name: Sarah Brown -brownsarahm@gh-inclass-brownsarahm $ echo "its finally fall" >> README.md -brownsarahm@gh-inclass-brownsarahm $ cat README.md +``` + +back as we wanted! + + + + ++++{"lesson_part":"site"} + +Typically, when we write to a file, in programming, we also have to tell it what *mode* to open the file with, and some options are: +- read +- write +- append + +This could be familiar from: +- `fopen` in C +- or `open` in Python ++++{"lesson_part":"main"} + +References + +- [C language docs from IBM](https://www.ibm.com/docs/en/zos/2.2.0?topic=functions-fopen-open-file) +- [Python official docs](https://docs.python.org/3/library/functions.html#open) + + +*C is not an open source language in the typical sense so there is no "official" C docs* ++++{"lesson_part":"main"} + +We can also **redirect** the contents of a command from stdout to a file in `bash`. Like file operations while programming there is a similar concept to this mode. + +There are two types of redirects, like there are two ways to write to a file, more generally: +- overwrite (`>`) +- append (`>>`) +- ++++{"lesson_part":"main"} + + +We can add contents to files with `echo` and `>>` + + ++++{"lesson_part": "main"} + +```{code-cell} bash +:tags: ["skip-execution"] +echo "its finally fall" >> README.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console +``` + ++++{"lesson_part":"main"} + +Then we check the contents of the file and we see that the new content is there. + +```{code-cell} bash +:tags: ["skip-execution"] +cat README.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console # GitHub Practice Name: Sarah Brown its finally fall -brownsarahm@gh-inclass-brownsarahm $ git status > curgit -brownsarahm@gh-inclass-brownsarahm $ ls +``` + + ++++{"lesson_part":"main"} + +We can redirect other commands too: + + +```{code-cell} bash +:tags: ["skip-execution"] +git status > curgit +``` + + + ++++{"lesson_part": "main"} +we see this created a new file +```{code-cell} bash +:tags: ["skip-execution"] +ls +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console API.md abstract_base_class.py scratch.ipynb CONTRIBUTING.md alternative_classes.py setup.py LICENSE.md curgit tests_alt.py @@ -269,7 +708,18 @@ README.md example.md tests_helpers.py _config.yml helper_functions.py tests_imp.py _toc.yml important_classes.py tsets_abc.py about.md philosophy.md -brownsarahm@gh-inclass-brownsarahm $ cat curgit +``` + ++++{"lesson_part": "main"} +and we can look at its contents too +```{code-cell} bash +:tags: ["skip-execution"] +cat curgit +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch organization Changes not staged for commit: (use "git add ..." to update what will be committed) @@ -281,16 +731,38 @@ Untracked files: curgit no changes added to commit (use "git add" and/or "git commit -a") -brownsarahm@gh-inclass-brownsarahm $ rm curgit -brownsarahm@gh-inclass-brownsarahm $ ls -API.md abstract_base_class.py setup.py -CONTRIBUTING.md alternative_classes.py tests_alt.py -LICENSE.md example.md tests_helpers.py -README.md helper_functions.py tests_imp.py -_config.yml important_classes.py tsets_abc.py -_toc.yml philosophy.md -about.md scratch.ipynb -brownsarahm@gh-inclass-brownsarahm $ git status +``` + ++++{"lesson_part": "main"} + +this is not a file we actually want, which gives us a chance to learn another new bash command: +`rm` for remove + +```{code-cell} bash +:tags: ["skip-execution"] +rm curgit +``` + + ++++{"lesson_part":"main"} + +Note that this is a true, full, and complete DELETE, this does not put the file in your recycling bin or the apple trash can that you can recover the file from, it is **gone** for real. + +We will see soon a way around this, because git can help. + +*use `rm` with great care* + + ++++{"lesson_part": "main"} + +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch organization Changes not staged for commit: (use "git add ..." to update what will be committed) @@ -298,22 +770,54 @@ Changes not staged for commit: modified: README.md no changes added to commit (use "git add" and/or "git commit -a") -brownsarahm@gh-inclass-brownsarahm $ git commit -a -m "add a note" +``` + ++++{"lesson_part": "main"} + +Now we have made some changes we want, so let's commit our changes. + + +```{code-cell} bash +:tags: ["skip-execution"] +git commit -a -m "add a note" +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console [organization 72b85c7] add a note 1 file changed, 1 insertion(+) -brownsarahm@gh-inclass-brownsarahm $ git status +``` + ++++{"lesson_part": "main"} + +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console On branch organization nothing to commit, working tree clean -brownsarahm@gh-inclass-brownsarahm $ touch cat -brownsarahm@gh-inclass-brownsarahm $ git status -On branch organization -Untracked files: - (use "git add ..." to include in what will be committed) - cat +``` + ++++{"lesson_part": "main"} + +```{code-cell} bash +:tags: ["skip-execution"] +git status +``` -nothing added to commit but untracked files present (use "git add" to track) -brownsarahm@gh-inclass-brownsarahm $ rm cat -brownsarahm@gh-inclass-brownsarahm $ echo "|file | contents | + + ++++{"lesson_part": "main"} +Now we will add some text to the readme + +```{code-cell} bash +:tags: ["skip-execution"] +echo "|file | contents | > > | --| -- | > > | abstract_base_class.py | core abstract classes for the project | > > | helper_functions.py | utitly funtions that are called by many classes | @@ -332,7 +836,18 @@ brownsarahm@gh-inclass-brownsarahm $ echo "|file | contents | > > | philosophy.md | overview of how the code is organized for docs | > > | example.md | myst notebook example of using the code | > > | scratch.ipynb | jupyter notebook from dev |" >> README.md -brownsarahm@gh-inclass-brownsarahm $ cat README.md +``` + ++++{"lesson_part": "main"} + +```{code-cell} bash +:tags: ["skip-execution"] +cat README.md +``` + ++++{"lesson_part": "main","type":"output"} + +```{code-block} console # GitHub Practice Name: Sarah Brown @@ -356,27 +871,105 @@ its finally fall > | philosophy.md | overview of how the code is organized for docs | > | example.md | myst notebook example of using the code | > | scratch.ipynb | jupyter notebook from dev | -brownsarahm@gh-inclass-brownsarahm $ git statu -git: 'statu' is not a git command. See 'git --help'. - -The most similar commands are - status - stage - stash -brownsarahm@gh-inclass-brownsarahm $ git status -On branch organization -Changes not staged for commit: - (use "git add ..." to update what will be committed) - (use "git restore ..." to discard changes in working directory) - modified: README.md +``` + ++++{"lesson_part":"main"} + +this explains each file a little bit more than the name of it does. +We see there are sort of 5 groups of files: +- about the project/repository +- code that defines a python module +- test code +- documentation +- extra files that "we know" we can delete. + +We also learn something about bash: +using the open quote `"` then you stay inside that until you close it. when you press enter the command does not run until after you close the quotes + + + ++++{"lesson_part": "main"} +Finally, we will commit the changes + +```{code-cell} bash +:tags: ["skip-execution"] +git commit -a -m 'explain files' +``` -no changes added to commit (use "git add" and/or "git commit -a") -brownsarahm@gh-inclass-brownsarahm $ git commt -a -m 'explain files' -git: 'commt' is not a git command. See 'git --help'. -The most similar command is - commit -brownsarahm@gh-inclass-brownsarahm $ git commit -a -m 'explain files' ++++{"lesson_part": "main","type":"output"} + +```{code-block} console [organization f17e276] explain files 1 file changed, 19 insertions(+) -brownsarahm@gh-inclass-brownsarahm $ +``` + + +## Prepare for Next Class + +```{include} ../_prepare/2024-09-24.md +``` + +## Badges + +`````{tab-set} +````{tab-item} Review +```{include} ../_review/2024-09-19.md +``` + +```` + +````{tab-item} Practice +```{include} ../_practice/2024-09-19.md +``` + +```` +````` + + + +## Experience Report Evidence + +Save your history with: +``` +history > activity-2024-09-19.md +``` + +## Questions After Today's Class + +### Would using > and >> locally create a merge conflict if the edited file also has a merge to it on Github? + +*any* edit to a file could create a merge conflict, so yes one wiht a redirect can + +### I would like to learn more about adding text into files, for example if you can add text in between specific lines when writing to a file + +This requires more complex commands than we will use in class time, but it can be done with [`sed`](https://www.gnu.org/software/sed/manual/sed.html). A tutorial on this could be a good {term}`explore` badge. + +### If I forgot to restore something for a couple of days and then chose to restore it a while later would I still be able to or is there a time limit to doing so? + +There is not a *time* limit, but if you did other operations it can require different commands beside `restore` + +### Can bash be used to trigger cursor events like mouse clicks? + +I do not think so, but a [headless browser](https://en.wikipedia.org/wiki/Headless_browser#:~:text=A%20headless%20browser%20is%20a,interface%20or%20using%20network%20communication.) allows you to automate browser operations, including selecting things that are most typically done by users with a mouse click, because in the browser clickable things are labeled in other ways. + +This is also a good {term}`explore` option. + +### What is different between using echo or nano to add to a file? + +Adding to a file with `echo` and a redirect is nice for adding small changes, but not extnsive changes or changes to the middle of a file. `nano` is a full text editor. In class today, `echo` was an easy way to demonstrate redirects, because it is so simple, but redirects are more powerful with more powerful commands. + +### A question that I have is about git pull, does it run git fetch beforehand to retrieve new content from the online repo Or is git pull just a completely different pocess to bring down content? + + +```{epigraph} +... precisely, `git pull` runs `git fetch` with the given parameters and then depending on configuration options or command line flags, will call either `git rebase` or `git merge` to reconcile diverging branches. + +-- [official docs](https://git-scm.com/docs/git-pull#:~:text=More%20precisely%2C%20git%20pull%20runs%20git%20fetch%20with%20the%20given%20parameters%20and%20then%20depending%20on%20configuration%20options%20or%20command%20line%20flags%2C%20will%20call%20either%20git%20rebase%20or%20git%20merge%20to%20reconcile%20diverging%20branches.) +``` + +example with diagrams [in last class](gitpull) notes + +### How do I create a community badge? + +[instructions in syllabus](../syllabus/badges.md#community-badges)