Used in data compression, search engines, password protection, fraud detection, and securing websites.
Central to technologies like Blockchain, Image Processing, and Load Balancing.
Functions and Hash Functions
Functions: Map an input to an output.
Pure Functions: Produce the same output for a given input, no side effects.
Impure Functions: Produce different outputs for the same input due to external factors.
Hashing: Converts input data to a fixed-length output (hash).
Hash Functions: Deterministic and produce fixed-length outputs.
Collisions in Hashing
Collisions: Different inputs produce the same hash output. They are inevitable due to the finite number of hash outputs compared to infinite potential inputs.
Pigeonhole Principle: Explains why collisions are unavoidable.
Collision Probability: Very low with SHA-1, similar to winning a lottery multiple times in a row.
SHA-1: Popular hashing algorithm used in Git.
Git Initialization
What is a Git Repository?
A Git repository (repo) is a virtual storage for your project, saving versions and tracking changes.
Create different repositories for different projects.
Creating and Initializing a Repository
git init: Initializes a new Git repository in your project directory, creating a hidden .git folder.
git status: Shows the state of the repository.
What is a Commit?
A commit saves the latest changes to the repository.
Captures a snapshot of the project's current state.
Each commit includes a message describing the changes made.
Git generates a unique hash for each commit.
Exploring the Staging Area
Staging Area in Git
Acts as an intermediary between the working directory and the repository.
Allows you to review and organize changes before committing.
Helps maintain a clear project history by grouping related changes.
Working with Multiple Files
Stage multiple files separately or together.
Stage all changes in the directory at once for efficiency.
Making a Commit
Steps to Make a Commit
git add <file>: Stages specified files or directories for the next commit.
git commit -m "message": Saves the staged changes to the repository with a commit message.
Tracking Changes
git status: Shows the state of the repository.
git diff: Shows differences between the working directory and the staging area.
Viewing Commit History
git log: Shows detailed commit history.
git log --oneline: Provides a simplified view of each commit.
Amending Commit Messages
git commit --amend -m "new commit message": Changes the message of the most recent commit.
Understanding Values and Hashes
Git as a Persistent Map
Git stores data as key-value pairs, with keys as unique hashes.
Keys and Values: Keys are unique SHA-1 hashes, values are the actual content.
SHA-1: Generates unique hashes for content.
Content Storage: Content is stored in the .git/objects directory.
Persistence in Git
Persistent Data: Data stored for future retrieval.
Generating Hashes: Use git hash-object to generate unique hashes for content.
Storing Content in Git
Content is saved in the .git/objects directory.
Viewing Stored Content: Use git cat-file to view stored content.
Using .gitignore
Purpose of .gitignore
Specifies files and directories that Git should ignore.
Keeps the repository clean and focused.
Creating a .gitignore File
Command: echo <pattern> >> .gitignore to add patterns.
Patterns can specify files, directories, or file types to ignore.
Patterns in .gitignore
Single File: filename
Directory: directory/
File Extension: .extension
Recursive Patterns: directory/**/file
Multiple Levels of .gitignore
Can be placed at different levels of the project directory.
Root-level .gitignore for global rules.
Module-level .gitignore for specific folders.
Understanding Git is crucial for effective project management and collaboration. For more detailed information, refer to the Notion link: