Q1Which is a correct statement of the difference between saving over a file and committing?
What Git Is — Recording Changes So You Can Go Back
This article is part of the IT Foundations course, which builds up from scratch the practical IT knowledge you need at a minimum for programming and vibe coding.
Saving over a file leaves nothing of the earlier state. Diagrams follow the flow from leaving a record with a commit to pulling an earlier point out of the records stacked up in the repository.
This article covers Git.
Git records changes to files so you can return to an earlier state, and putting those records on a server lets you bring other people to the same state.
The records lined up in the three places are the same, and a server in between is what brings them into line.
What Git does — leaving records, and sharing them through a remote
Recording changes to files point by point so that a past state can be pulled back out is version control.
The place those records are kept is a repository, the same thing placed on a server is a remote repository, and one record is a commit.
The best-known services for hosting a remote repository are GitHub and GitLab, and GitHub is not Git itself; it is a place to put a remote repository.
- app.js and style.css
- Saving over them replaces the contents
- Commits lined up oldest first
- git commit adds one
- Commits sent with git push line up here
- https://github.com/example/my-app.git is that place
- Can be read and written from another computer
Sending the records on your computer to the server is a push, and taking the records on the server in is a pull.
Because a server sits in between, the contents are the same whenever the coworker takes them in.
The Git wording that appears in instructions falls into three kinds.
The left column stays inside your computer, while the middle and right ones exchange with GitHub.
Saving over a file leaves no earlier state — what version control records
Saving over a file replaces the contents of app.js with the current contents.
Nothing of the old contents is left after the replacement, so no amount of saving lets you return to an earlier state.
| What you did before editing | Where the old contents are | After it stops working |
|---|---|---|
| Only saved over it | Nowhere | Cannot go back |
| Left the editor open | The undo history (gone when you close it) | Edits made while it is open can be undone |
| Ran git commit | The record in the repository | Can go back at any time |
Only when you have committed do the old contents stay in the repository.
The only dividing point is whether you ran git commit once before editing.
That one command creates a point you can return to.
Only a commit leaves a record
Saving over a file erases the old contents with the current ones, and what is erased is left nowhere on the computer.
A commit adds a record of app.js as it stands at that point, without erasing anything, so when things stop working, the only points you can go back to are the ones you committed.
A commit has two stages: choose the changes to record, then leave the record
A commit is split into two stages: you choose first, and record afterward.
The stage where you choose and register changes is staging, and because of these two stages there are three places to hold things inside the my-app folder.
- app.js — the contents open in the editor now
- style.css — the file that describes how the screen looks
- Saving over them replaces the contents here
- Holds the changes chosen with git add
- Goes back to empty when you run git commit
- Commits lined up oldest first
- git commit adds one
A change moves from top to bottom in two steps: git add and git commit.
The change to index.html that you did not choose is not lost, and you can choose it next time.
The steps for checking before you record come out as these three lines.
# Check which files you edited
git status
# Choose and register the changes to record
git add app.js
# Record the chosen changes with a short message
git commit -m "Add the login screen"
Running git status lists the names of the files you edited, and git log shows the list of records.
If you run git commit without having run git add, no changes have been chosen, so no record is created.
Choose what to record before you record it
A commit has two stages: choosing and recording.
git add chooses the changes that go into this record and git commit turns only what you chose into one record, so if you forget the choosing step, not a single record is added.
The repository sits inside the folder, with commits lined up oldest first
The dedicated folder that holds the repository is created the moment you run git init, which starts recording in that folder.
Every time you commit, the records inside it grow by one.
- app.js as it was when you built the screen
- The date and time and the message "Create the screen"
- app.js and style.css as they were when you added the input fields
- The date and time and the message "Add the input fields"
- The most recently recorded app.js
- The date and time and the message "Add the login screen"
Going back means choosing one of the records lined up there and replacing the app.js you are working on with its contents.
For files you do not want recorded, you can write their names in a settings file called .gitignore inside the folder.
This keeps files that have not been recorded yet from being recorded, and it has no effect on a file that has been recorded once.
Records are not lost; they line up oldest first
The repository is inside the dedicated folder in the my-app folder.
Every time you commit the records grow by one, and earlier records are never rewritten, so going back means choosing one of the records lined up there and making the current file hold its contents.
Knowledge Check
Answer each question one by one.
Q2A commit is split into two stages. Which stage comes before the record is left?
Q3Which operation sends a commit left in the repository on your computer to the remote repository on a server?