Skip to content

ReZeroS/git

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

  1. 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
  2. zit init - Initialize the .zit directory with an objects subdirectory, create an index file (stage area), and set the default main branch

    • The default HEAD file content is ref: ref/heads/main
  3. 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}
  4. zit cat-file hash [object|tree|commit|...type] - Print the file content

  5. zit write-tree - Generate a tree describing the entire repository

    • Executed after the add command, creating a tree from the index file
  6. zit read-tree hash

    • Caution: This action will delete all existing content before reading
    • Use cat-file to find the root tree
    • Logs from write-tree can also help you find all trees
  7. While write-tree can save versions, it lacks context information, so a zit commit -m "message" command is needed

    • Use cat-file hash commit-id to check commit content
    • HEAD will record the commit with its parent
  8. Enjoy committing and use log to view commit history

  9. Checkout: Select a commit ID from the log and 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...)
  10. tag will alias a commit ID, introducing a core concept

    • git-ref official post helps learn basic reference knowledge
  11. TODO: zit lg graph feature with Graphviz

  12. zit branch name [id] - Familiar branch creation

    • Every ref under refs/heads is treated as a branch
    • File content is simply the commit ID, defaulting to the head point
  13. zit show will display detailed changes using diff, while status shows simple change information

  14. zit add adds files or directories to the stage file: .zit/index

  15. zit commit calls write-tree and updates the HEAD pointer to the commit ID

    • First-time usage creates the default main branch and rewrites the HEAD file content
    • Merge HEAD is deleted, and the message is added to the commit message
  16. zit status shows 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)
  17. zit diff uses the Myers diff algorithm without linear space refinement optimization

  18. zit reset changes HEAD to the current commit (difference from checkout is pending)

  19. zit merge checks 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_head in the zit root directory, requiring manual commit
    • zit merge-base helps find the first common parent commit for merging and debugging
  20. zit fetch and zit push download 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
  • Ugit uses Pythonic code, while zit aims to make the code easily understandable for developers of other languages

TODO

  1. git hash-object improvement: 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