Skip to content

Latest commit

 

History

History
111 lines (70 loc) · 3.89 KB

File metadata and controls

111 lines (70 loc) · 3.89 KB

Step 3: Exploring Git History

Now that our game is tracked in Git, let's learn how to explore what changes were made, when, and by whom.

📖 Theory: Understanding Git History

Git maintains a complete history of your project through commits. Each commit contains:

  • Unique hash ID: A unique identifier to easily reference it in the history.
  • Parent commit: Reference to the previous commit, creating a chain.
  • Author information: Who made the changes.
  • Timestamp: When the changes were applied.
  • Commit message: Description of the changes included in that commit.

Additionally, the HEAD pointer is a special label that indicates your current position in the project history. Your project probably looks similar to the below diagram:

---
config:
  theme: 'forest'
---
gitGraph
   commit id: "9c6ef8a Initial commit"
   commit id: "16ac970 Start game documentation"
   commit id: "762ac02 Start developer docs" tag: "HEAD"
Loading

Git History Commands

Everyone prefers viewing the history in different ways, and the community has created many options. Here are a few of the common commands and options you will often use:

  • git log - Displays a detailed history of the project.
    • git log --oneline - Shows one commit per line, but with less detail.
    • git log --graph - Shows a visual diagram, useful for diverging branches.
  • git checkout - Moves to a different point in the history (modifies files in your working directory).

⌨️ Activity 1: Explore the history (using the CLI)

  1. Show the detailed commit history.

    git log
  2. Show one commit per line.

    git log --oneline
  3. Show a visual graph of the commit history.

    git log --graph --oneline

    🪧 Note: This will look more interesting in a future step when the history is longer.

  4. Copy the Commit ID of the Initial commit entry. Both the long and short form will work.

  5. Use it to checkout the earlier version.

    git checkout <commit id>


    🪧 Notice the README.md file was removed.

  6. Return to the latest commit on main. Notice the README.md file has returned. 🧐

    git checkout main


⌨️ Activity 2: Explore the history (using VS Code)

  1. In the left navigation, open the Source Control tab.

  2. Right-click on the Changes header and enable the Graph option.

  3. Inspect the Graph panel. Notice the timeline list of your recent commits.


  4. Click the commit names to expand a list of the files modified by that commit.

  5. With your exploration of the Git history complete, Mona should already be busy checking your work. Give her a moment and keep watch in the comments. You will see her respond with progress info and the next steps.

Having trouble? 🤷
  • Use git log --help to see all available options for viewing history.