This project is a minimal implementation of Git in C++, replicating core Git functionalities such as object storage, indexing, and tree management. The goal is to understand Git's internals by building a working model of its key commands.
The current implementation supports the following Git commands:
git init– Initializes a new Git repository.git cat-file -p <object>– Displays the content of a Git object.git hash-object <file>– Computes the SHA-1 hash of a file.git hash-object -w <file>– Computes the SHA-1 hash and writes the object to the.git/objectsdirectory.git ls-tree <tree>– Lists the contents of a tree object.git ls-tree -r <tree>– Recursively lists the contents of a tree object.git ls-tree -l <tree>– Lists tree contents with object size.git ls-files– Shows the tracked files in the index.git write-tree– Converts the index into a tree object.git add .– Adds files to the index.
To build and run the project, ensure you have a C++ compiler installed (GCC/Clang/MSVC) and CMake for build management.
cmake --debug-output -B build -S .
cmake --build buildInitialize a repository:
./git-cpp initAdd files to the index:
./git-cpp add .Write the index to a tree:
./git-cpp write-treeList files in the index:
./git-cpp ls-filesInspect a tree:
./git-cpp ls-tree <Tree-hash>Compute and store a file’s hash:
./git-cpp hash-object -w myfile.txtRetrieve an object’s content:
./git-cpp cat-file -p <object-hash>.git-cpp/
├── src/ # Source code
├── include/ # Header files
├── build/ # Compiled binaries
├── .git/ # Git metadata when initialized
└── README.md # Project documentation
- Implement
git commit - Implement
git checkout - Implement
git clone - Optimize object storage
- Add unit tests
Contributions are welcome! Feel free to submit issues or pull requests to improve the project.