NUS Hackers Wiki
NUS Hackers Wiki
  • NUS Hackers Wiki
  • Hackerschool
    • Virtual Machines and Linux
    • Beginners' Guide to the Terminal
      • Introduction to the Terminal
      • Modern Shell Tools
      • Shell Scripting
      • Real World Scripting
      • Resources
    • Self-Hosting: Three Easy Pieces
      • 1. Setting up your server
      • 2. Running Services
      • 3. Monitoring your server
    • Vim
    • Introduction to Zig
      • Language Basics
      • Error Handling
      • Memory Management
      • Working with C
      • Exploring comptime
    • CI/CD with Github Actions
      • Background
      • Basics of Github Actions
        • Target workflow
        • Running unit tests
        • Linting code
        • Deploying to Github Pages
      • Advanced use cases
        • Pollers
        • Github script
        • Executing third-party scripts
        • Reusable workflows
      • Cookbook
    • Lightning Git
      • Git Concepts
      • Getting Started with Git
      • Making your first commit
      • Branching
      • Merge Conflicts
      • Integrating remote repositories
      • Collaborative Workflows
      • Commit Manipulation and Reflog
      • Interactive rebasing
      • filter-repo
  • Orbital
    • JavaScript
      • Browser Developer Tools
      • Getting Started
      • Datatypes
      • Operators and Operations
      • Loops and Conditions
      • Functions
      • Strings
      • Arrays
      • HTML
        • Getting Started
        • Tag Attributes
        • HTML Forms
        • Browser Inspector
      • CSS
        • Selectors
        • Colors in CSS
        • Measurements in CSS
        • The Box Model
        • Adding Styles - Part 1
        • Adding Styles - Part 2
      • Working with the DOM
        • Querying the DOM - Selectors
        • Querying the DOM - Element Attributes
        • Querying the DOM - Element Styles
        • Events with JS and HTML
        • Exercise: Click Counter
        • Editing the DOM
        • Fetch Requests
        • Exercise: The NUSMods API
    • React
      • Setup
      • State
    • React Native
      • Setup
      • Intro to JSX
      • Basic Syntax
      • Handling UI
      • Props
      • State Management
    • Git
      • Setup
      • Command Glossary
      • Fundamental Concepts
        • Getting Started
        • Integrating Remote Repositories
        • Branching
        • Merge Conflicts
      • Collaborative Workflows
        • Fork and PR Workflow
        • Branch and PR Workflow
      • Advanced Concepts
        • Ignoring Files
        • Commit Message Conventions
        • Github Collaborators
        • CI/CD with Github Actions
        • Advanced Git Commands
      • FAQ
    • Telegram Bot
      • Creating a TeleBot
      • API Calls
      • Telebot Basics
      • Integrating API's
    • Relational Database
      • Database Overview
      • Database Design
      • Entity Relationship Diagram
      • SQL Basics & PostgreSQL
    • TypeScript
      • Types and Interfaces
      • Utility Types
      • Typing Component Props, Events, and Hooks
      • Why You Should Avoid Using any (and What to Do Instead)
      • TypeScript Tricks You’ll Use All the Time in React
Powered by GitBook
On this page
  • git log: View commit details
  • git revert: Revert a commit
  • git reset: Reset HEAD to the commit
  • git checkout: Checkout files (and also a branch) commits
Edit on GitHub
Export as PDF
  1. Orbital
  2. Git
  3. Advanced Concepts

Advanced Git Commands

PreviousCI/CD with Github ActionsNextFAQ

Last updated 12 months ago

: View commit details

Sample output of git log. Use j and k on the keyboard to scroll up and down and q to exit the log view.

commit 4bdffb07c5abd0d41388c991dc03661be07fe6d0 (HEAD -> main, origin/main, origin/HEAD)
Merge: 269f9f4 11690c2
Author: Jiahao <woojiahao1234@gmail.com>
Date:   Fri May 17 21:46:40 2024 +0800

    Merge pull request #7 from francisyzy/main
    
    Update links

commit 11690c25ce187263ff77725647475fee6d5e1faa
Author: francisyzy <francisyzy@me.com>
Date:   Fri May 17 21:37:24 2024 +0800

    Add feedback QR code

commit f5458f36c67c927fcd41e65e29eb5b8a1491d7a1
Author: francisyzy <francisyzy@me.com>
Date:   Fri May 17 17:14:09 2024 +0800

    Update links

commit 269f9f48ddb550da9223d03123279910dd8c5336
Merge: a1fc9bf 01cdd59
Author: Francis Yeo <github@francisyzy.com>
Date:   Fri May 17 12:15:50 2024 +0800

    Merge pull request #3 from woojiahao/main

Each log entry will describe what that commit does. Each commit will have a commit hash, author and date.

For example this commit:

commit f5458f36c67c927fcd41e65e29eb5b8a1491d7a1
Author: francisyzy <francisyzy@me.com>
Date:   Fri May 17 17:14:09 2024 +0800

    Update links
  • commit hash is f5458f36c67c927fcd41e65e29eb5b8a1491d7a1

  • author is francisyzy <francisyzy@me.com> which was set by the author's git config

  • date of the commit is Fri May 17 17:14:09 2024 +0800

  • message of the commit is Update links

Lets you 'undo' a commit. It will undo the changes made by that commit and make a new commit to do so.

Do note that this is not the method of removing sensitive information as commit history can still retrieve it.

This will reset the current HEAD to the commit hash.

Useful reset command that can be used to edit the commit message before its being pushed to the remote is: git reset --soft HEAD~. The command will reset the files to the commit right before the current commit and leave the files in the latest commit in staged. Allowing you to git commit -m "Updated message" to change the git commit message.

You can also use git checkout <commit hash> to go to view the files at a specific commit too.

A useful feature to have when you want to check out the files of that commit before you reset to that commit.

The git commit history is also viewable on the itself.

: Revert a commit

There is a on how to remove such information and rewrite history. Do note that rewriting history will result in other people's repo being broken.

: Reset HEAD to the commit

: Checkout files (and also a branch) commits

git log
Github repository
git revert
stackoverflow discussion
git reset
git checkout