Version Control (Week 1) Flashcards
What is version control
It refers to the management of changes to documents, programs and other information stored in computer files. It stores all the revisions made to a file with timestamps. (Sometimes it only stores the differences -called diffs- between the file versions, rather than an entire copy of the file.)
Why is version control good?
Makes it easy to review or go back to specific versions later on
What is centralized version control?
One central repository
- All users commit their
changes to a central
repository
-Each user (client) has a
working copy. As soon as
they commit, the repository
gets updated
What is Distributed Version control?
Multiple copies of repository
* Each user commits to a local
(private) repository
* All committed changes
remain local unless pushed to
another repository
* No external changes are visible unless pulled from another repository (you only see what you’ve pulled in, not what others have done unless you go get it)
* Examples include Git, Hg (Mercurial), BitKeeper
For distributed version control how does cloning work, and what do u get when you clone something?
you clone the full project to your own computer.Then, when others make changes, you can pull those changes to update your copy.
You’re not just getting the files—you get the entire version history. Your copy works the same as the original on the server. This also means you automatically create a backup, which is useful if the server crashes.
Meaning of repository?
The database storing the files
Meaning of Add?
Put a file into the repo for the first time, i.e.,
begin tracking it with version control
(Basically saying, “Start paying attention to this file and include it in the next commit- begin tracking the file for version history.)
Meaning of Revision?
A revision is just a version of a file.
Every time you make a change and commit it, the file gets a new revision.
These versions are usually labeled like: v1, v2, v3, and so on.
So, if you’re on revision v3, it means the file has been updated (and committed) three times since it was first added.
Check out
Set the current version of the file from the repo - switching to a specific version or branch of the project. You’re telling the system:
“I want to work with this version now.”
Commit
Write changes to repository. (Move stagged changes to the repo)
git commit -m “comment”
Head
Sucking penis. Jk. The latest revision in the repo OR pointer to current branch. (This is like a bookmark showing where you are in the project. It usually points to the most recent commit on the current branch.)
Branch
Establishes a ‘fork’ of the code that may be developed independently (This lets you create a separate line of development, so you can try new features or fixes without affecting the main project. You can merge it back later if it works out.)
Git uses branching heavily to switch between multiple task
git branch branchname (creates a new branch)
git branch (lists all the branches)
git checkout branchname (Switch to a specific branch)
Merge
Combining changes from multiple branches
git merge
What are the two ways to create a git repository?
Way 1:
- Create a new local repo in directory (git innit). This creates a .git directory in your current directory.
- Then you can commit files in that directory into the repository. (git add filename, git commit -m “commit message.”)
Way 2:
- Clone a remote git repo to the current directory (git clone WEBSITE). This will create the given local directory, containing
a working copy of the files from the repo, and a .git directory (used to hold the staging area and your actual local repo). Creates an exact copy of the repository in the current local directory.
What is the staging area (also called index)
Staged files are ready to be commited. Commiting something saves a snapshot of all the staged files.
In git, to add something it means to add it to the staging area so its part of the next commit
.git directory
.git directory
This directory is automatically created when you initialize a Git repository with git init.
It’s located at the top level of a Git project.
It contains everything Git needs to manage the version control, including:
All objects (like commits, blobs, trees)
Configuration files (specific to this repo)
References to branches and tags
Inside .git, there’s a file called config (.git/config), which stores project-specific settings (e.g., remotes, merge settings).
~/.gitconfig
This is the global Git configuration file, usually located in your home directory.
It stores settings like your username, email, default editor, and aliases that apply across all repositories on your system.
.gitignore
This is a plain text file where you list files or patterns for Git to ignore.
Useful for ignoring:
Build files
Temporary files
IDE-specific files (like .vscode/, .DS_Store)
Ensures you don’t accidentally commit unnecessary or sensitive files.
Lets say you have a file called penis.pdf and u don’t want it to commit the changes you must create a file called ,gitignore and add the line penis.pdf then save. and it will not track or include the file in commits.
How to undo changes on a file before you commit it?