git
git copied to clipboard
Simple git implemented by java.
GIT Development Log
Thanks for the great tutorial: https://www.leshenko.net/p/ugit
Thanks again, Nikita!
Resources
I found some good reference materials and placed them in the ./doc directory.
Additionally, these links might be helpful:
- Nick Butler: A concise post that provides a high-level understanding of diff
- jcoglan: A detailed description of the diff algorithm
- Visualization: A great resource for debugging or visualizing the diff algorithm
- PDF: A short PDF about Git that I hope you'll find interesting
If you're interested in this project, feel free to share your ideas in the discussion or contact me via email.
Usage
-
alias zit='java -jar ../zit-1.0-SNAPSHOT-shaded.jar'- Alias the zit executable file- On Windows, you can set this in
C:\Program Files\Git\etc\profile.d\aliases.sh
- On Windows, you can set this in
-
zit init- Initialize the.zitdirectory with anobjectssubdirectory, create an index file (stage area), and set the defaultmainbranch- The default HEAD file content is
ref: ref/heads/main
- The default HEAD file content is
-
zit hash-object file- Get the file path to store
- Read the file
- Hash the content of the file using SHA-1
- Store the file under
.ugit/objects/{the SHA-1 hash}
-
zit cat-file hash [object|tree|commit|...type]- Print the file content -
zit write-tree- Generate a tree describing the entire repository- Executed after the
addcommand, creating a tree from the index file
- Executed after the
-
zit read-tree hash- Caution: This action will delete all existing content before reading
- Use
cat-fileto find theroottree - Logs from
write-treecan also help you find all trees
-
While
write-treecan save versions, it lacks context information, so azit commit -m "message"command is needed- Use
cat-file hash commit-idto check commit content HEADwill record the commit with its parent
- Use
-
Enjoy committing and use
logto view commit history -
Checkout: Select a commit ID from the
logand verify the state- [Fixed with getBytes(Charsets.UTF-8)] Bug: Chinese file or directory names may appear garbled
- Arguments can be head alias, hash, or ref (branch, tags, HEAD...)
-
tagwill alias a commit ID, introducing a core concept- git-ref official post helps learn basic reference knowledge
-
TODO:
zit lggraph feature with Graphviz -
zit branch name [id]- Familiar branch creation- Every ref under
refs/headsis treated as a branch - File content is simply the commit ID, defaulting to the head point
- Every ref under
-
zit showwill display detailed changes using diff, whilestatusshows simple change information -
zit addadds files or directories to the stage file:.zit/index -
zit commitcallswrite-treeand updates the HEAD pointer to the commit ID- First-time usage creates the default
mainbranch and rewrites the HEAD file content - Merge HEAD is deleted, and the message is added to the commit message
- First-time usage creates the default
-
zit statusshows the current situation- If not in a detached HEAD state, logs the current HEAD-pointed branch
- Logs merge hash ID if in a merge state
- Lists changes to be committed (diff between HEAD tree and index)
- Lists changes not staged for the next commit (diff between index and working tree)
-
zit diffuses the Myers diff algorithm without linear space refinement optimization -
zit resetchanges HEAD to the current commit (difference fromcheckoutis pending) -
zit mergechecks if the merge base equals the head, using fast-forward merge if possible- Fast-forward requires no commit
- Otherwise, uses diff3 to merge the merge base, head tree, and other tree
- Leaves
merge_headin the zit root directory, requiring manual commit zit merge-basehelps find the first common parent commit for merging and debugging
-
zit fetchandzit pushdownload or upload objects and update references
Summary
UPDATED 2021.02.21
- Implemented diff (Myers diff without linear space optimization) and merge algorithms (simple diff3) instead of using Unix tools
Ugituses Pythonic code, while zit aims to make the code easily understandable for developers of other languages
TODO
git hash-objectimprovement: When real Git stores objects, it:- Writes the object size to the file
- Compresses objects
- Divides objects into 256 directories to avoid performance issues with large numbers of files