TerryLikesCoding Blog

website·Indexed 29 days ago

https://terrylikescoding.github.io/

A technical blog featuring guides and tutorials on Git version control (including rebase, cherry-pick, and reset), Spring Boot development, Docker basics, and Hexo Markdown configurations.

Tokens
16.9K
Snippets
123
Records
143
Agent score
74%

What's inside TerryLikesCoding

  1. Inspect remote branch information

    To view the current state of branches on a remote server without downloading the data to your local working directory, you can use git ls-remote. To get more detailed configuration information about a specific remote (such as fetch/push URLs and tracked branches), use git remote show.
    # List remote references
    git ls-remote origin
    
    # Show detailed information for a specific remote
    git remote show origin
  2. Understand the Git workflow using the Three Trees model

    Git manages files across three distinct states (trees):

    1. Working Directory: The actual files on your disk that you are editing.
    2. Index (Staging Area): A snapshot of the files you intend to include in the next commit.
    3. HEAD: The snapshot of the current commit the project is pointing to.

    Standard Workflow:

    • Modify: Changes are made in the Working Directory. git status shows these as 'Changes not staged for commit' (red).
    • Stage: git add <file> moves changes from the Working Directory to the Index. git status shows these as 'Changes to be committed' (green).
    • Commit: git commit moves the snapshot from the Index to HEAD. All three trees are now synchronized.
  3. Inspect and manage remote repository configurations

    You can view detailed information about a remote, rename a remote shorthand, or remove a remote reference entirely.
    # View detailed info for a remote (e.g., origin)
    git remote show origin
    
    # Rename a remote shorthand (e.g., rename 'pb' to 'paul')
    git remote rename pb paul
    
    # Remove a remote reference
    git remote rm paul
  4. Understand the Git Three-Tree Mental Model

    Git manages project state by manipulating three distinct collections of files, referred to as 'trees'. Understanding these is key to mastering commands like git reset and git checkout.

    • HEAD: A pointer to the current branch's latest commit. It represents the snapshot of the last commit and serves as the parent for the next commit.
    • Index (Staging Area): A snapshot of what the next commit is expected to look like. When you run git add, files are moved from the working directory to the index.
    • Working Directory: The actual files on your disk (the 'sandbox') where you edit code before staging or committing them.
  5. Inspect Git objects using git show

    The git show command is used to inspect different types of Git objects. The output varies depending on the object type:

    • Commits: Displays the log message and the textual diff.
    • Tags: Displays the tag information and the object it references.
    • Trees: Displays the names of the entries (similar to git ls-tree --name-only).
    • Blobs: Displays the actual content of the blob.
    git show [<options>] [<object>…]
  6. Understanding Microservice Architecture

    Microservices is an architectural style where a single application is developed as a suite of small services. Key characteristics include:

    • Process Isolation: Each service runs in its own process, allowing for independent deployment and upgrades.
    • Lightweight Communication: Services typically interact via HTTP resource APIs.
    • Business-Centric: Services are built around specific business capabilities.
    • Decentralization: Services are autonomous and can be written in different programming languages or use different data storage technologies.
    • Automated Deployment: Services are independently deployable via automated machinery.
  7. Understand Git's internal storage and commit objects

    Git does not store file changes or diffs; instead, it stores a series of snapshots of files at different points in time. When a commit is made, Git creates a commit object containing: a pointer to a snapshot of the staged content, the author's name and email, the commit message, and a pointer to the parent commit(s). The first commit has no parent; normal commits have one; merge commits have multiple. Git uses SHA-1 hashes to create tree objects (representing directory structures) and blob objects (representing file contents) to reconstruct these snapshots.
  8. Apply multiple commits using git cherry-pick

    You can apply multiple commits at once by listing multiple hashes or by using a range operator. The range startHash^..endHash picks all commits from startHash to endHash (inclusive of both).
    # Pick multiple specific commits
    git cherry-pick <hash1> <hash2> <hash3>
    
    # Pick a range of commits (from startHash to endHash inclusive)
    git cherry-pick <startHash>^..<endHash>
  9. Create a local branch from a remote tracking branch

    When you fetch data from a remote, Git creates a remote-tracking pointer (e.g., origin/serverfix) which is read-only. To work on this branch locally, you must create a local branch based on that pointer.
    # Create a local branch 'serverfix' tracking 'origin/serverfix'
    git checkout -b serverfix origin/serverfix
  10. Fetch data from a remote repository

    Use git fetch to download all data from a specified remote repository that you do not yet have. This updates your local references to the remote branches but does NOT automatically merge the changes into your current working branch. You must manually merge the changes after fetching.
    git fetch <remote-name>
    
    # Example: fetch from the default 'origin' remote
    git fetch origin