J O S E P H J O S E P H

Git

Commits

reset

Resets the current branch HEAD to a given state. Use with caution.

git reset <commit>    # Reset to a specific commit

# Options
--hard      # Unstage changes and delete changes from the working directory
--soft      # Keep unstaged and working directory changes

# Example: Reset HEAD to origin/main
git fetch origin
git reset --hard origin/main

revert

Creates a new commit at HEAD that reverts all changes from the commit passed to revert.

git revert <commit>

# Options
--no-edit   # Use the original commit message, prepended w/ the word "Revert"

rev-parse

Fetch the current HEAD commit SHA.

git rev-parse HEAD

--amend

Amends the most recent commit. Commonly used to change the commit message, but it can also be used to add additional (staged) changes to the most recent commit. Changes the commit SHA.

# Amend commit message for most recent commit
git commit --amend -m "<new_message>"

# Amend the latest commit without changing the commit message
git commit --amend --no-edit

Branches

--unset-upstream

Removes upstream tracking of a branch. If no branch is specified it defaults to the current branch.

git branch --unset-upstream <branch>

rev-parse (for branch)

Fetch the current HEAD branch name.

git rev-parse --abbrev-ref HEAD

Logs

--pretty=short --graph

Minimizes the commit details and displays a text-based graphical representation of the git history in the output.

git log --pretty=short --graph