Skip to content

Commit

Permalink
update text to match the new example; closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Jan 26, 2025
1 parent e8a5fc2 commit c4ca239
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 43 deletions.
16 changes: 13 additions & 3 deletions content/version-control/branching-and-committing.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Illustration of what we want to achieve in this exercise.
1. First create a new branch and then either add a new file or modify an
existing file and commit the change. Make sure that you now work **on your
copy** of the example repository. In your new commit you can share a Git or
programming trick you like.
programming trick you like or improve the documentation.
1. In a new commit, modify the file again.
1. Switch to the `main` branch and create a commit there.
1. Browse the network and locate the commits that you just created ("Insights" -> "Network").
Expand All @@ -58,6 +58,16 @@ Illustration of what we want to achieve in this exercise.
1. Try to rename the branch that you created and then browse the network again.
1. Try to create a tag for one of the commits that you created (on GitHub,
create a "release").
1. Optional: If this was too easy, you can try to create a new branch and on
this branch work on one of these new features:
- The random seed is now set to a specific number (42). Make it possible to
set the seed to another number or to turn off the seed setting via the command line interface.
- Move the code that does the majority vote to an own function.
- Write a test for the new majority vote function.
- The `num_neighbors` in the code needs to be odd. Change the code so that it stops with an error message if an even number is given.
- Add type annotations to some functions.
- When calling the `scatter_plot` function, call the function with named arguments.
- Add example usage to README.md.
:::

The solution below goes over most of the answers, and you are
Expand Down Expand Up @@ -208,7 +218,7 @@ it makes sense later on.
::::{group-tab} GitHub
A nice way to compare branches is to add `/compare` to the URL of the repository,
for example (replace USER):
https://github.com/**USER**/planets/compare
https://github.com/**USER**/classification-task/compare
::::

::::{group-tab} VS Code
Expand Down Expand Up @@ -241,7 +251,7 @@ This is similar to above, but not only between branches.
::::{group-tab} GitHub
Following the `/compare`-trick above, one can compare commits on GitHub by
adjusting the following URL:
https://github.com/**USER**/planets/compare/**VERSION1**..**VERSION2**
https://github.com/**USER**/classification-task/compare/**VERSION1**..**VERSION2**

Replace `USER` with your username and `VERSION1` and `VERSION2` with a commit hash or branch name.
Please try it out.
Expand Down
50 changes: 25 additions & 25 deletions content/version-control/browsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ It is also possible to do this: to clone a forked repository to your computer.

At all times you should be aware of if you are looking at **your repository**
or the **upstream repository** (original repository):
- Your repository: https://github.com/**USER**/planets
- Upstream repository: https://github.com/**workshop-material**/planets
- Your repository: https://github.com/**USER**/classification-task
- Upstream repository: https://github.com/**workshop-material**/classification-task

:::{admonition} How to create a fork
1. Go to the repository view on GitHub: <https://github.com/workshop-material/planets>
1. Go to the repository view on GitHub: <https://github.com/workshop-material/classification-task>
1. First, on GitHub, click the button that says "Fork". It is towards
the top-right of the screen.
1. You should shortly be redirected to your copy of the repository
**USER/planets**.
**USER/classification-task**.
:::

:::{instructor-note}
Expand Down Expand Up @@ -95,7 +95,7 @@ Work on this by yourself or in pairs.
In this case you will work on a fork.

You only need to open your own view, as described above. The browser
URL should look like https://github.com/**USER**/planets, where
URL should look like https://github.com/**USER**/classification-task, where
USER is your GitHub username.
::::

Expand All @@ -110,7 +110,7 @@ locally.
open), go to File → New Window.
1. Under "Start" on the screen, select "Clone Git Repository...". Alternatively
navigate to the "Source Control" tab on the left sidebar and click on the "Clone Repository" button.
1. Paste in this URL: `https://github.com/USER/planets`, where
1. Paste in this URL: `https://github.com/USER/classification-task`, where
`USER` is your username. You can copy this from the browser.
1. Browse and select the folder in which you want to clone the
repository.
Expand All @@ -134,30 +134,30 @@ locally.
(`cd ~/code` for example, if the `~/code` directory is where you
store your files).
1. Run the following command: `git clone
https://github.com/USER/planets`, where `USER` is your
https://github.com/USER/classification-task`, where `USER` is your
username. You might need to use a SSH clone command instead of
HTTPS, depending on your setup.
1. Change to that directory: `cd planets`
1. Change to that directory: `cd classification-task`
::::
:::::
::::::


:::{exercise} Exercise: Browsing an existing project (20 min)

Browse the [example project](https://github.com/workshop-material/planets) and
Browse the [example project](https://github.com/workshop-material/classification-task) and
explore commits and branches, either on a fork or on a clone. Take notes and
prepare questions. The hints are for the GitHub path in the browser.

1. Browse the **commit history**: Are commit messages understandable?
(Hint: "Commit history", the timeline symbol, above the file list)
1. Compare the commit history with the **network graph** ("Insights" -> "Network"). Can you find the branches?
1. Try to find the **history of commits for a single file**, e.g. `simulate.py`.
1. Try to find the **history of commits for a single file**, e.g. `generate_predictions.py`.
(Hint: "History" button in the file view)
1. **Which files include the word "position"**?
1. **Which files include the word "training"**?
(Hint: the GitHub search on top of the repository view)
1. In the `simulate.py` file,
find out who modified the "time step"
1. In the `generate_predictions.py` file,
find out who modified the evaluation of "majority_index"
last and **in which commit**.
(Hint: "Blame" view in the file view)
1. Can you use this code yourself? **Are you allowed to share
Expand All @@ -178,7 +178,7 @@ The most basic thing to look at is the history of commits.

* This is visible from a button in the repository view. We see every
change, when, and who has committed.
* Every change has a unique identifier, such as `244c993`. This can
* Every change has a unique identifier, such as `79ce3be`. This can
be used to identify both this change, and the whole project's
version as of that change.
* Clicking on a change in the view shows more.
Expand Down Expand Up @@ -263,12 +263,12 @@ for a single file.
:::::{tabs}

::::{group-tab} GitHub
Navigate to the file view: Main page → simulate.py.
Navigate to the file view: Main page → generate_predictions.py.
Click the "History" button near the top right.
::::

::::{group-tab} VS Code
Open simulate.py file in the editor. Under the file browser,
Open generate_predictions.py file in the editor. Under the file browser,
we see a "Timeline" view there.
::::

Expand All @@ -277,14 +277,14 @@ The `git log` command can take a filename and provide the log of only
a single file:

```
$ git log simulate.py
$ git log generate_predictions.py
```
::::

:::::


### (4) Which files include the word "position"?
### (4) Which files include the word "training"?

Version control makes it very easy to find all occurrences of a
word or pattern. This is useful for things like finding where functions or
Expand All @@ -293,7 +293,7 @@ variables are defined or used.
:::::{tabs}
::::{group-tab} GitHub
We go to the main file view. We click the Search magnifying
class at the very top, type "position", and click enter. We see every
class at the very top, type "training", and click enter. We see every
instance, including the context.

:::{admonition} Searching in a forked repository will not work instantaneously!
Expand All @@ -306,16 +306,16 @@ Start it, continue with other steps, then come back to this.

::::{group-tab} VS Code
If you use the "Search" magnifying class on the left sidebar, and
search for "position" it shows the occurrences in every file. You can
search for "training" it shows the occurrences in every file. You can
click to see the usage in context.
::::

::::{group-tab} Command line
`grep` is the command line tool that searches for lines matching a term
```console
$ git grep position # only the lines
$ git grep -C 3 position # three lines of context
$ git grep -i position # case insensitive
$ git grep training # only the lines
$ git grep -C 3 training # three lines of context
$ git grep -i training # case insensitive
```
::::

Expand Down Expand Up @@ -344,8 +344,8 @@ line version, after opening a terminal.
::::{group-tab} Command line
These two commands are similar but have slightly different output.
```console
$ git annotate simulate.py
$ git blame simulate.py
$ git annotate generate_predictions.py
$ git blame generate_predictions.py
```
::::

Expand Down
Binary file modified content/version-control/img/browsing/history.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified content/version-control/img/browsing/network.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified content/version-control/img/illustrations/clone-of-fork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified content/version-control/img/illustrations/clone.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions content/version-control/img/illustrations/drawing.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified content/version-control/img/illustrations/fork.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions content/version-control/motivation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ of them?):

## Demonstration

- Example repository: <https://github.com/workshop-material/planets>
- Example repository: <https://github.com/workshop-material/classification-task>
- Commits are like **snapshots** and if we break something we can go back to a
previous snapshot.
- Commits carry **metadata** about changes: author, date, commit message, and
a checksum.
- **Branches** are like parallel universes where you can experiment with
changes without affecting the default branch:
<https://github.com/workshop-material/planets/network>
<https://github.com/workshop-material/classification-task/network>
("Insights" -> "Network")
- With version control we can **annotate code**
([example](https://github.com/workshop-material/planets/blame/main/simulate.py)).
([example](https://github.com/workshop-material/classification-tas/blame/main/generate_predictions.py)).
- **Collaboration**: We can fork (make a copy on GitHub), clone (make a copy
to our computer), review, compare, share, and discuss.
- **Code review**: Others can suggest changes using pull requests or merge
Expand All @@ -70,15 +70,15 @@ Image created using <https://gopherize.me/>

- **Collaboration**: review, compare, share, discuss

- [Example network graph](https://github.com/workshop-material/planets/network)
- [Example network graph](https://github.com/workshop-material/classification-task/network)


## Talking about code

Which of these two is more practical?
1. "Clone the code, go to the file 'simulate.py', and search for 'force_between_planets'.
Oh! But make sure you use the version from September 2024."
1. Or I can send you a permalink: <https://github.com/workshop-material/planets/blob/1343ac0/simulate.py#L31C5-L39>
1. "Clone the code, go to the file 'generate_predictions.py', and search for 'majority_index'.
Oh! But make sure you use the version from January 2025."
1. Or I can send you a permalink: <https://github.com/workshop-material/classification-task/blob/79ce3be8/generate_predictions.py#L25-L28>


## What we typically like to snapshot
Expand Down
2 changes: 1 addition & 1 deletion content/version-control/practical-advice.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ this is based on a discussion in #123
- **Why something was changed is more important than what has changed.**
- Cross-reference to issues and discussions if possible/relevant.
- Bad commit messages: "fix", "oops", "save work"
- Bad examples: [http://whatthecommit.com](http://whatthecommit.com)
- Just for fun, a page collecting bad examples: [http://whatthecommit.com](http://whatthecommit.com)
- Write commit messages that will be understood
15 years from now by someone else than you. Or by your future you.
- Many projects start out as projects "just for me" and end up to be successful projects
Expand Down
2 changes: 2 additions & 0 deletions content/version-control/sharing.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,5 @@ accessible**, consider making your code **citable and persistent**: Get a
persistent identifier (PID) such as DOI in addition to sharing the code
publicly, by using services like [Zenodo](https://zenodo.org) or similar
services.

More about this in {doc}`../publishing`.

0 comments on commit c4ca239

Please sign in to comment.