git allows you to bundle up changes to various files, and give the group of changes a unique commit hash and an explanatory message.
git works on a project level, so you can make a bunch of changes to different files in a folder, and then commit all those changes with a descriptive message
It’s recorded that you made those changes, and there’s a unique commit hash that you can quote to point at the exact state of your folder when you added those changes.
What does git do?
git is a command line program
There are actually only a few commands you’ll really use regularly
But before we move on to learning what commands are needed, let’s try to build a mental model of git
Hopefully this will be useful to those of you who are already using git too!
What does git do?
Old version of python-file.py
1 # This is a comment
2 import matplotlib.pyplot as plt
3 x = [1, 2, 3, 4, 5]
4 y = [3, 4, 5, 6, 7]
5 plt.scatter(x, y)
New version of python-file.py
1 # This is a comment
2 import matplotlib.pyplot as plt
3 import numpy as np
4 x = [1, 2, 3, 4, 5]
5 y = [3, 4, 5, 6, 7]
6 plt.scatter(x, y)
6 plt.plot(x, y)
Line 3 added,line 6 removed,line 6 added.
What does git do?
New version of python-file.py
1 # This is a comment
2 import matplotlib.pyplot as plt
3 import numpy as np
4 x = [1, 2, 3, 4, 5]
5 y = [3, 4, 5, 6, 7]
6 plt.scatter(x, y)
6 plt.plot(x, y)
Line 3 added,line 6 removed,line 6 added.
Associated git commit
File: python-file.py
Commit hash: u87wy9o2
Commit message: change plotting method
+++ 3 import numpy as np
- – 6 plt.scatter(x, y)
+++ 6 plt.plot(x, y)
What does git do?
When we work with git, we bundle up changes in our project folder (/directory) and commit our changes.
Each commit (bundle of changes) gets a unique id - a hexadecimal hash that’s 40 digits long (we’re just going to abbreviate to the first 7)
When we are happy with our bundle of changes, we close up the basket and commit the changes, and add a nice little label to it in the form of a commit message
The git cycle
Some new jargon - the state of the files in your repository
Untracked/modified: files that have been created or edited since the last cycle, that haven’t been added or committed
Staged: files that have been added (put in the basket) but not committed yet.
Committed: files that have been added and committed and now have a unique id attached to their most recent changes (and have not been edited since the last commit)
As well as being able to “undo” entire commits, you can undo different stages of this cycle (e.g. you can unstage files so they go from being staged to untracked)
Maeve’s mammoth commit
Maeve’s picnic commit was pretty big!
What if she wants to remove the fruit without removing the sandwich and smoothie?
In practice, aim to keep commits small and focused on a specific update or bugfix