Update git course with exercises and some more advanced material#268
Update git course with exercises and some more advanced material#268fcooper8472 wants to merge 2 commits into
Conversation
martinjrobins
left a comment
There was a problem hiding this comment.
thanks @fcooper8472, changes look great, a few suggestions below
|  | ||
|
|
||
| Fundamentally, though, these are all just 'wrappers' around the command line version of Git. | ||
| If you understand what they're doing under the hood, you can easily switch between versions. You can, for example, manage your code on Iridis using command-line git and GitHub Desktop on your desktop workstation. |
There was a problem hiding this comment.
looks like southamptons supercsomputer
|
|
||
| :::callout | ||
|
|
||
| ## Git GUI Integrations |
There was a problem hiding this comment.
| ## Git GUI Integrations | |
| ## Git IDE Integrations |
| A colleague is about to put their research project into Git. Which of the following would you recommend they track, and which would you leave out? | ||
|
|
||
| 1. Their analysis scripts (`analysis.py`) | ||
| 2. A 2 GB raw data file downloaded from a public archive |
There was a problem hiding this comment.
you don't discuss anywhere above what can and can't be tracked
| ... | ||
| ``` | ||
|
|
||
| By default, `restore` replaces the file with the version of it in the _staging area_. If you haven't used `git add`, that should be the same as the version in the last commit. But what if we already used `git add` on our incorrect version of a file, or we broke the file more than one commit ago? |
There was a problem hiding this comment.
one thing I found confusing looking at the git documentation was that the staging area is usually called the "index", not sure if you mention that anywhere
| Consider a situation where all your code is in one file, | ||
| and you fixed a bug in one section but accidentally introduced one elsewhere. | ||
|
|
||
| You can't just roll back to fix one bug without un-fixing the other. |
There was a problem hiding this comment.
well, you can fairly easily if you are in an IDE. or (more difficult) you can use the interactive mode of git to do it line by line
| :::callout | ||
| If the change you're reverting overlaps with later edits, Git may not be able to | ||
| work out how to undo it automatically and will report a **conflict**. If that | ||
| happens, resolve it by hand exactly as you did for merge conflicts in the previous |
There was a problem hiding this comment.
I don't remember if merge conflicts were covered?
There was a problem hiding this comment.
in 06-remote.md, so after this.
| The remaining modules in this course are optional and marked _(Advanced)_. Come | ||
| back to them whenever you meet the problem each one solves: | ||
|
|
||
| - **Rebasing and Squashing**: produce a clean, linear history. |
There was a problem hiding this comment.
put links to these modules
| them, rebasing will rewrite commits that others already have - and things will | ||
| get badly tangled. | ||
|
|
||
| Only rebase commits that are still **private** to your local repository. If in |
There was a problem hiding this comment.
or in a private branch on the remote
There was a problem hiding this comment.
I think in general this callout both undersells rebase, cause it is useful even on shared work, and also
“Never rebase anything already pushed” obscures the actual danger. Rebasing creates new commit identities; if someone has fetched or based work on the original commits, their history will diverge and they must reconcile it after the rewritten branch is force-pushed.
But rebasing pushed feature, draft-PR, backport branches is routine when ownership is clear and collaborators are coordinated. Could this callout instead say: Do not rebase commits that other people may be using without coordinating with them first?
| ## Setting work aside with `git stash` | ||
|
|
||
| Before you can `git pull`, you need to have committed any changes you have made. | ||
| But what if you want to pull, and you're **not ready to commit**? You can | ||
| temporarily "put aside" your uncommitted changes with `git stash`: | ||
|
|
||
| ```bash | ||
| git stash | ||
| git pull | ||
| ``` | ||
|
|
||
| Stashing takes your uncommitted changes off the working directory and saves them | ||
| away, leaving your repository clean so the pull can proceed. When you're ready, | ||
| bring your changes back with: | ||
|
|
||
| ```bash | ||
| git stash pop | ||
| ``` | ||
|
|
||
| (`git stash apply` does the same but keeps a copy in the stash list; `git stash | ||
| list` shows what you have stashed.) The stash is a great way to save your working | ||
| state in a pinch - for example when you need to quickly switch branches to fix | ||
| something urgent. |
There was a problem hiding this comment.
Think this should include that git stash only stashed changes in tracked files, so it will leave untracked files.
Could also include "git stash -u" for stashing untracked files.
| :::callout | ||
| If the change you're reverting overlaps with later edits, Git may not be able to | ||
| work out how to undo it automatically and will report a **conflict**. If that | ||
| happens, resolve it by hand exactly as you did for merge conflicts in the previous |
There was a problem hiding this comment.
in 06-remote.md, so after this.
|
|
||
| ## Referencing remotes | ||
|
|
||
| When you run `git fetch`, Git downloads the latest state of a remote **without** |
There was a problem hiding this comment.
because this is right after saying git remote add upstream then perhaps it is not transparent enough that this will only fetch origin and not upstream (add -all or specifically call out git fetch upstream)
| For example, `git clean -fdX` clears out everything your `.gitignore` matches | ||
| (such as generated `*.pdf` or `__pycache__` files) while leaving new source files | ||
| you haven't committed yet untouched. |
There was a problem hiding this comment.
I think this perhaps is a bad command to have as ane xample, someone is likely to run it and lose files? could you do the preview version. -ndX? and have the callout indicate that omitting the -n from git clean is dangerous
| A `git merge` is only one of two ways to combine someone else's work (or the work | ||
| on another branch) with your own. The other is called a **rebase**. | ||
|
|
||
| - In a **merge**, Git adds a new _merge commit_ that brings the two branches | ||
| together. **Both histories are kept**, and the graph shows a divergence | ||
| followed by a convergence. |
There was a problem hiding this comment.
I felt that this misrepresented git merge (which as you explain later can fast forward)
| A `git merge` is only one of two ways to combine someone else's work (or the work | |
| on another branch) with your own. The other is called a **rebase**. | |
| - In a **merge**, Git adds a new _merge commit_ that brings the two branches | |
| together. **Both histories are kept**, and the graph shows a divergence | |
| followed by a convergence. | |
| Merging and rebasing are two common ways to combine work from different branches: | |
| - When **diverged branches are merged**, Git preserves their existing commits and normally creates a new _merge commit_ that joins the two histories. |
| ```bash | ||
| python -m pytest tests/test_conversion.py # passes? | ||
| git bisect good | ||
|
|
||
| python -m pytest tests/test_conversion.py # fails? | ||
| git bisect bad | ||
| ``` |
There was a problem hiding this comment.
I think it is better to explain this like:
| ```bash | |
| python -m pytest tests/test_conversion.py # passes? | |
| git bisect good | |
| python -m pytest tests/test_conversion.py # fails? | |
| git bisect bad | |
| ``` | |
| ```bash | |
| python -m pytest tests/test_conversion.py | |
| ``` | |
| If it passes, mark the current commit as good: | |
| ```bash | |
| git bisect good | |
| ``` | |
| Or, if it fails, mark the current commit as bad: | |
| ```bash | |
| git bisect bad | |
| ``` |
| :::callout{variant="tip"} | ||
| This is a strong argument for keeping a good test suite: with automated tests, | ||
| finding _when_ a regression was introduced becomes a single command. | ||
| ::: |
There was a problem hiding this comment.
I mean it isnt a single command, requires setup and repeated commands but shall we say...
| :::callout{variant="tip"} | |
| This is a strong argument for keeping a good test suite: with automated tests, | |
| finding _when_ a regression was introduced becomes a single command. | |
| ::: | |
| :::callout{variant="tip"} | |
| This is a strong argument for keeping a good test suite: with automated tests and bisect, | |
| finding _when_ a regression was introduced becomes a much simpler process. | |
| ::: |
| If `..` is used with nothing after it, `HEAD` is assumed, so `v1.0..` means | ||
| "everything after v1.0, up to now". |
There was a problem hiding this comment.
Since "everything after v1.0" implies a linear history, IK thought the following was better
| If `..` is used with nothing after it, `HEAD` is assumed, so `v1.0..` means | |
| "everything after v1.0, up to now". | |
| If `..` is used with nothing after it, `HEAD` is assumed. | |
| This lists commits reachable from HEAD that are not part of v1.0. | |
| In a simple linear history, these are the commits made since the release. |
|
|
||
| | Centralised (cvs, svn) | Distributed (git, mercurial) | | ||
| | ---------------------------------- | ------------------------------------- | | ||
| | Server holds the history | Every clone has the _full_ history | |
There was a problem hiding this comment.
aorry, peantry drives this cahnge (sahllow clones)
| | Server holds the history | Every clone has the _full_ history | | |
| | Server holds the history | A normal clone has the _full_ history | |
| Older version control systems (like CVS and Subversion) were **centralised**: the | ||
| history lived only on a server, and almost every operation required an internet | ||
| connection. |
There was a problem hiding this comment.
I think this perhaps minimsed these toosl, both that they needed internet,might be a locla server, and that every opoeration needed the server.
Add:
The main additions are migrating the remaining content from this course:
https://github.com/OxfordRSE/git-github-course
The more advanced material is marked as such, so minor content changes for someone just starting with Git, but some stretch material for people more familiar.
The other major change is adding some exercises. They're fairly trivial, but hopefully will help improve engagement.
(There are a large number of whitespace changes, Windows to Unix endings... @alasdairwilson dunno if it's worth a one-time normalisation of line endings and some instrumentation to catch this on PRs in future, to avoid future large diffs?)