Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

LyrineYang/gitLet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Gitlet: A Git-like Version Control System

License: MIT

This repository contains a personal implementation of a Git-like version control system, based on Project 2 from the UC Berkeley CS61B course. It is designed to simulate the core functionalities of Git, providing a deep, practical understanding of version control mechanics.

该存储库是加州大学伯克利分校 CS61B 课程项目的一个个人实现,旨在模拟 Git 的核心功能,以深入理解版本控制系统的内部工作原理。

This project successfully passed all 1600/1600 points on the course's autograder, validating its functional correctness according to the project specifications.


📜 Declaration of Originality & Course Context

This project is a personal implementation based on Project 2: Gitlet from the CS61B course at the University of California, Berkeley.

All core logic code independently written by me is marked with @author Lyrine Yang at the beginning of the respective Java files. Other parts of the project not explicitly authored by me, or originating from the course materials, may include skeleton code or utility classes provided by the UC Berkeley CS61B course.

This project is intended solely for educational and skill demonstration purposes. If any part of this project is deemed to infringe upon your rights, please contact me via email at [email protected], and I will promptly address the matter and remove the content as necessary.


✨ Features 功能

Gitlet replicates many of Git's essential commands, offering a robust feature set for version control.

  • Repository Management

    • init: Creates a new Gitlet repository.
    • status: Shows the current status of the repository, including branches, staged files, and modifications.
  • File Tracking & Committing

    • add: Adds file contents to the staging area.
    • commit: Saves a snapshot of the staging area to the repository.
    • rm: Unstages a file and removes it from the working directory.
  • History & Inspection

    • log: Displays the commit history of the current branch.
    • global-log: Shows the history of all commits ever made in the repository.
    • find: Finds all commits with a given commit message.
  • Branching & Navigation

    • branch: Creates a new branch.
    • checkout: Restores files to a previous state or switches branches.
    • rm-branch: Deletes a branch.
    • reset: Resets the current branch head to a specified commit.
  • Merging

    • merge: Merges changes from another branch into the current branch, including automatic conflict detection.

🛠️ Design and Implementation 设计与实现

Gitlet's design is heavily inspired by the architecture of Git itself, centered around a few core concepts.

  • The .gitlet Directory: All metadata, including commits, blobs, and branch information, is stored in a hidden .gitlet directory at the project root. This centralizes the repository's state.

  • Content-Addressable Storage:

    • Blobs: The content of every tracked file is stored as a "blob" object. Each blob is named by the SHA-1 hash of its content, ensuring that identical files are stored only once.
    • Commits: Each commit is an object containing metadata (message, timestamp, parent commit hash) and a tree mapping filenames to blob hashes. A commit's ID is also the SHA-1 hash of its contents, making the entire history immutable.
  • Staging Area (index): A crucial intermediate layer between the working directory and the commit history. The add command stages changes in the index, and commit records the state of the index as a new snapshot.

  • Branching and Merging:

    • Branches are lightweight pointers to commits. The HEAD file points to the currently active branch.
    • Merging is implemented using a three-way merge strategy, which involves finding the Lowest Common Ancestor (LCA) between the two branches to intelligently merge changes and identify conflicts. The LCA-finding algorithm was carefully designed to correctly handle complex histories involving previous merges.

🚀 How to Run

This project requires Java 24 or higher.

  1. Compile the source code:

    javac gitlet/*.java
  2. Run Gitlet commands:

    java gitlet.Main <command> [operands]

    Examples:

    # Initialize a repository
    java gitlet.Main init
    
    # Add a file and commit it
    java gitlet.Main add README.md
    java gitlet.Main commit -m "Add project README"
    
    # Check the commit history
    java gitlet.Main log

🌟 Acknowledgements

  • Special thanks to my collaborator Yuteng Huang for being a great partner in programming.
  • Thanks to Noah He, shLin, Jiang Zhuo, and bzWang for their support and for making the journey enjoyable.
  • Thanks to Professor Josh Hug and the entire CS61B staff for creating this excellent and challenging project.

📜 License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A simple implement of version control system from git. CS61b lecture project.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published