Xit - A Simple Git-like Tool in Rust
Xit is a command-line tool that mimics some of the basic functionalities of Git. It is written in Rust and serves as a learning project to understand the inner workings of a version control system.
Features
- Repository Initialization: Create a new
.xit-like repository structure. - User Configuration: Set up a global user name and email.
- File Staging: Add files to an index (staging area).
- Committing: Create commits with a message.
- Ignoring Files: Use a
.xitignorefile to exclude files and directories from being tracked. - Viewing Repository Status: Display changes staged for commit, unstaged changes, and untracked files.
- Colored Output: User-friendly colored output for status and messages.
Commands
Here are the commands currently supported by Xit:
-
xit init: Initializes a new repository in the current directory. It creates a.xitdirectory with the necessary subdirectories and files. -
xit setup: Interactively prompts you to set up your global user name and email. This information is stored in~/.xit/configand used for commits. -
xit add <file>: Adds a file to the staging area (the index). The file's content is stored as a blob object. -
xit commit -m "<message>": Creates a new commit with the staged files. It creates a commit object and a tree object to represent the state of the repository. -
xit status: Shows the status of the working tree with color-coded output. It lists changes staged for commit (green), changes not staged for commit (red), and untracked files (red).
Ignoring Files (.xitignore)
You can create a .xitignore file in the root of your repository to tell xit to ignore certain files and directories. This works similarly to Git's .gitignore.
Each line in the .xitignore file specifies a pattern. xit will not track any files or directories matching these patterns. The implementation currently ignores any path component that matches a line in the file (e.g., target will ignore any directory named target anywhere in the project).
By default, xit ignores .xit, .git, and target.
Installation
You can install xit from crates.io using cargo (once it's published):
This will install the xit binary in your Cargo bin directory (e.g., ~/.cargo/bin), so you can run it from anywhere.
Alternatively, you can build it from source:
-
Clone the repository:
-
Build and run:
Example Workflow
Once xit is installed, you can use it in any directory to manage your projects.
# 1. Create a new directory for your project
# 2. Initialize a new Xit repository
# 3. Set up your identity (only needs to be done once)
# 4. Create a file and add it
# 5. Create a file to ignore
# 6. Create a .xitignore file
# 7. Check the status (logs/ will be ignored)
# 8. Commit the changes