sarabjeet_sgit
v1.0.0
Published
Sgit is a lightweight, custom version control system designed to mimic the core functionalities of Git. It enables you to track changes to files, stage them, and commit them with ease, offering basic functionality like logging commits and displaying diffe
Readme
Sgit - A Simple Version Control System
Sgit is a lightweight, custom version control system designed to mimic the core functionalities of Git. It enables you to track changes to files, stage them, and commit them with ease, offering basic functionality like logging commits and displaying differences between file versions.
Features
- Initialize a new repository with a
.Sgitdirectory - Add files to the staging area
- Commit changes with a message
- Log commit history
- Show diffs between committed versions
- Status of staged files
Installation
Clone this repository and navigate to the directory:
git clone https://github.com/Sarabjeet31/Version-control.git
cd sgitInstall the necessary dependencies using npm:
npm installUsage
Initialize a repository
To initialize a new Sgit repository in the current directory:
npx sgit initThis creates a .Sgit directory, which will store all objects and commit information.
Add files
To add a file to the staging area:
npx sgit add <filename>Example:
npx sgit add sample.txtCommit changes
After staging files, commit them with a message:
npx sgit commit "Your commit message"Example:
npx sgit commit "Initial commit"View commit log
To view the commit history:
npx sgit logShow differences
To see the changes between the current commit and the previous one:
npx sgit show <commitHash>Example:
npx sgit show 7b9d7266145f34073d310f02d42568c6c3213bb4Check staged files status
To check the status of the staged files:
npx sgit statusHow It Works
init: Creates a.Sgitdirectory that contains anobjectsfolder for storing file contents and commits.add: Reads the content of the file, generates a SHA1 hash, and stores it in theobjectsdirectory. Updates the index with the file’s hash.commit: Creates a commit object that references the current state of the files, with a commit message and the parent commit (if any).log: Displays a history of all commits made in the repository.show: Displays the diff between the current commit and its parent (if available).status: Displays the status of staged files with their respective hashes.
Dependencies
- Commander - For handling command-line input.
- Chalk - For colored terminal output.
- Diff - For displaying file differences.
- Crypto - For generating SHA1 hashes.
