DEV Community

Kervie Sazon
Kervie Sazon

Posted on

Git & GitHub Notes - Part 3: Undoing Changes & Forking

Undoing Changes

git reset
This command allows you to move the HEAD (current commit pointer) to a previous commit.

git log

Before undoing commits, itโ€™s useful to see the commit history.

Example Output:

commit d00cb3c91f942a4aa10c3d14e2428344e670e9d5 (HEAD -> testing-lang)
Author: Kervie Jay <166139157+kervieszn14@users.noreply.github.com>
Date:   Fri Mar 6 09:23:19 2026 +0800

    Update README.md

commit 896d60f6a6f5f695da06349bed40f530bf083413
Author: Kervie Jay <166139157+kervieszn14@users.noreply.github.com>
Date:   Fri Mar 6 09:21:59 2026 +0800

    README.md

commit 389969f59a98fe3496660f59a301f8ded48a74fb
Author: Kervie Jay <166139157+kervieszn14@users.noreply.github.com>
Date:   Fri Mar 6 09:20:26 2026 +0800
Enter fullscreen mode Exit fullscreen mode

Each commit has a unique commit hash which can be used to reset to a specific commit.

git reset HEAD~1

This command moves the repository one commit back.

Meaning:

  • HEAD - current commit
  • ~1 - one commit before the current commit

This removes the latest commit but keeps the changes in working directory so you can edit them again.

git reset <hash>

Used to reset a specific commit using its commit hash.

Example

git reset d00cb3c91f942a4aa10c3d14e2428344e670e9d5 
Enter fullscreen mode Exit fullscreen mode

This moves the project back to that commit.
Use git log to find the commit hash.

git reset --hard <hash>

This command resets the repository completely to a previous commit.

Example

git reset d00cb3c91f942a4aa10c3d14e2428344e670e9d5
Enter fullscreen mode Exit fullscreen mode

Important:

This will:

  • Remove commits after the selected commit
  • Delete changes in the working directory

Forking a Repository

Forking is a feature on GitHub that allows you to create a copy of someone else's repository under your own GitHub account.

After forking, you can clone your fork to your local machine.

Example:

git clone https://github.com/yourusername/project-name.git
Enter fullscreen mode Exit fullscreen mode

Then you can make changes and commit them normally.

Example workflow:

git add .
git commit -m "Improve documentation"
git push
Enter fullscreen mode Exit fullscreen mode

This pushes the changes to your forked repository.

Creating a Pull Request

After editing your fork, you can submit your changes back to the original project using a Pull Request (PR).

A Pull Request allows the original repository owner to:

  • Review your changes
  • Discuss improvements
  • Merge your contribution

Steps:

  1. Push changes to your fork
  2. Go to your forked repository on GitHub
  3. Click Compare & Pull Request
  4. Add a description
  5. Submit the Pull Request
Command Purpose
git log View commit history
git reset Move to a previous commit
git reset HEAD~1. Undo the last commit
git reset <hash> Reset to a specific commit
git reset --hard <hash> Reset and Delete Changes

Today, I learned how to undo commits in Git using commands like git reset and git reset --hard. I also practiced viewing commit history with git log to identify which commit to revert to. In addition, I learned how forking works on GitHub and how it allows developers to contribute to projects they donโ€™t own. Finally, I understood the workflow of editing a forked repository and submitting contributions through a Pull Request.

Top comments (0)