Use the checklist to tick off the sub-tasks as you complete them. Some of the tasks rely on material that has already
been covered in the lesson so try and use what you have learnt. The commands are provided if required though.
You have now used git commit --amend, lets try git commit --fixup.
Checkout the zero-division-amend-fixup branch
This branch doesn't exist so needs creating.
git switch -c zero-division-amend-fixup
Rebase the branch onto main
We need to ensure we have an up-to-date version of main before we can rebase onto it.
git switch main
git pull
git switch -
git rebase main
Add example of zero division to docstring
Copy and paste the following into the Examples section of the divide() function in the pythonmaths/arithmetic.py
file. Note it deliberately contains a spelling error as we will be fixing them. Make sure the code is correctly indented.
>>> arithmetic.divide(3, 0)
You can not divide by 0, please chose another value for 'y'.
Commit your changes
git add -u
git commit -m "docs: Adding zero division example to divide docstring"
Correct the spelling error
Did you spot it? The example above had chose instead of choose which is the actual error message returned. Correct
this in the docstring so it reads as shown below.
>>> arithmetic.divide(3, 0)
You can not divide by 0, please choose another value for 'y'.
Amend the previous commit
Rather than making a new commit amend the previous commit with the change.
git add -u
git commit --amend
Make an empty commit
git commit --allow-empty -m "Empty commit to try out fixup"
Add another example to the divide() function's example section
Add another example to the Examples section of the divide() function in the pythonmaths/arithmetic.py file.
>>> arithmetic.divide(1, 0.1)
10
Commit the change as a fixup
You need to know the hash of the commit made above that you amended (use git log --oneline) or you can use the
relative reference HEAD~1
git add -u
git commit --fixup HEAD~1
Perform an interactive rebase to automatically squash the changes
You will either need the hash of the commit before the one you are fixing up (use git logp to find this) or
you can use HEAD~3 (the fixup itself is currently a commit and so you have to go back an extra commit relative to
HEAD).
git rebase -i --autosquash HEAD~3
A text editor should open and the commit with the message staring fixup! should have fixup and not pick next to
it. If that isn't the case change it to fixup. Save the file and exit the text editor (this should be nano in which
case use Ctrl + o followed by Ctrl + x).
Remove the empty commit and push your changes
We can remove the empty commit and push our changes.
git reset HEAD~1
git push
Make a pull request and once approved merge
Go to GitHub and make a pull request to merge you changes in, assigning it to you have teamed up with for this
exercise. Once approved merge the pull request to main.
Delete your local zero-division-amend-fixup branch
We can now switch to main, pull down the merged changes and delete the local copy of the zero-division-amend-fixup
git switch main
git pull
git branch -d zero-division-amend-fixup
Use the checklist to tick off the sub-tasks as you complete them. Some of the tasks rely on material that has already
been covered in the lesson so try and use what you have learnt. The commands are provided if required though.
zero-division-amend-fixupbranch.mainto ensure it is up-to-date (Hint - you may not have all changes that have beenmerged into
main).divide()function that shows the consequence of trying todivide by zero.
You have now used
git commit --amend, lets trygit commit --fixup.divide()function's example section.zero-division-amend-fixupbranchCheckout the
zero-division-amend-fixupbranchThis branch doesn't exist so needs creating.
Rebase the branch onto
mainWe need to ensure we have an up-to-date version of
mainbefore we can rebase onto it.Add example of zero division to docstring
Copy and paste the following into the
Examplessection of thedivide()function in thepythonmaths/arithmetic.pyfile. Note it deliberately contains a spelling error as we will be fixing them. Make sure the code is correctly indented.
>>> arithmetic.divide(3, 0) You can not divide by 0, please chose another value for 'y'.Commit your changes
git add -u git commit -m "docs: Adding zero division example to divide docstring"Correct the spelling error
Did you spot it? The example above had
choseinstead ofchoosewhich is the actual error message returned. Correctthis in the docstring so it reads as shown below.
>>> arithmetic.divide(3, 0) You can not divide by 0, please choose another value for 'y'.Amend the previous commit
Rather than making a new commit amend the previous commit with the change.
Make an empty commit
git commit --allow-empty -m "Empty commit to try out fixup"Add another example to the
divide()function's example sectionAdd another example to the
Examplessection of thedivide()function in thepythonmaths/arithmetic.pyfile.>>> arithmetic.divide(1, 0.1) 10Commit the change as a fixup
You need to know the hash of the commit made above that you amended (use
git log --oneline) or you can use therelative reference
HEAD~1Perform an interactive rebase to automatically squash the changes
You will either need the hash of the commit before the one you are fixing up (use
git logpto find this) oryou can use
HEAD~3(the fixup itself is currently a commit and so you have to go back an extra commit relative toHEAD).A text editor should open and the commit with the message staring
fixup!should havefixupand notpicknext toit. If that isn't the case change it to
fixup. Save the file and exit the text editor (this should benanoin whichcase use
Ctrl + ofollowed byCtrl + x).Remove the empty commit and push your changes
We can remove the empty commit and push our changes.
Make a pull request and once approved merge
Go to GitHub and make a pull request to merge you changes in, assigning it to you have teamed up with for this
exercise. Once approved merge the pull request to main.
Delete your local
zero-division-amend-fixupbranchWe can now switch to
main, pull down the merged changes and delete the local copy of thezero-division-amend-fixup