Materials originally developed for the "Version control for research" breakout session of the Best Practice for Code Archiving workshop, 11 December 2016.
One of the powerful functions of git is that it allows you to go back to an earlier version of your code if you’ve made a mistake. We don’t have time to cover this in the workshop but here are some basic pointers.
It’s easy to forget to make a change or to add a file that you wanted
to include in a commit. Provided you haven’t already pushed your
changes you can easily adjust the latest commit. Make the necessary
changes, use git add
to mark the modified files to be committed,
then run:
git commit --amend
This will re-run the previous commit with the additional changes that you’ve made. You can use this command on its own if you just want to adjust your commit message.
If you forget the -m
on your git commit
it will open your system’s
default text editor in your terminal. If you’re unfamiliar with the
way the editor works it can be hard to know how to exit from the
editor. If this catches you out, try the following:
Esc
then :x
If that doesn’t work, this question has been asked a million times on stack exchange so Google is your friend.
You’re likely to come across other issues when using git. Have a look at oh shit git! for how to fix some other common problems.
Next: Summary