> ## Content Index
> Fetch the complete content index at: https://www.techielass.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Undoing commits & changes - 14 days of Git
- URL: https://www.techielass.com/undoing-commits-changes/
- Published: 2022-09-23T07:01:19.000Z
- Updated: 2022-09-23T07:01:19.000Z
- Description: Join me on my Git learning journey as I look at what commands can help you undo commits and changes within your repository.
- Author: Sarah Lean
- Tags: 14daysofgit, Git for everyone, Git

We are on day 7 of my 14 days of Git learning journey, so far, I have explored: 

- [What is version control?](https://www.techielass.com/what-is-version-control)
- [What is Git?](https://www.techielass.com/what-is-git)
- [Installing Git](https://www.techielass.com/installing-git/)
- [Basic Git commands to get started](https://www.techielass.com/basic-git-commands-to-get-started)
- [Inspect a Git repository](https://www.techielass.com/inspect-a-git-respository)
- [Git File Operations](https://www.techielass.com/git-file-operations)

Now it's time to start looking at how you can undo commits and changes to your repository!

## Undoing commits & changes

There are times where you will be made a commit and realised that you want to undo that for whatever reason. 

What's the best of doing that though? Deleting the file, you just created, deleting the line you wrote in a file? What happens when you've made a ton of changes and don't remember all the bits that need undone now? 

This is where git revert, and git reset can help. 

## Git Revert

Git revert is a command that can remove all the changes a single commit made to your repository. 

When you revert a Git commit the changes from that commit are remove from your local workspace. And a new commit is created to reflect the new state of your repository.

Let's show this in action. 

I issue a command to create a new file, called *index.md* and add and commit that file. 

![Add a new file and commit to the repository](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2022/09/image-2.png)

Add a new file and commit to the repository

If I want to revert that commit I first need to use the command *git reflog* to get more details about that commit. 

![git reflog output](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2022/09/image-3.png)

git reflog output

The *git reflog* command gives me the commit number that I need in order to revert that commit. 

In this case I want to revert commit *93a79b1.*

I can now issue the command ***git revert 93a79b1***

Because this command is creating a new commit, I was asked what I wanted the new commit message to reflect. 

It's important to remember with this command, you are only reverting the commit you aren't erasing the history of the commit. So, any changes can still be referenced within the history of the repository. 

## Git Reset

With Git revert we just undid changes from a specific commit. However, there might be occasions where you want to revert every change that has happened since a given commit. 

This is where the *git reset* command can be used. 

The steps to use Git reset are: 

1. Use *git reflog* to get the commit number you wish to reset to
2. Issue the command *git reset number*
3. The repository will not reset your repository to the state it was at that choosen commit

Again, with the *git reset* command remember that you are just reverting to a previous state, you aren't removing the history. It will still be there to see and refer to. 

## 14 days of Git

It's been interesting today to look at how to undo changes or move to another time in history for the repository. There is two clear use cases and differences for *git reset* and *git revert*.   
  
Good to expand my knowledge and learn more commands from the Git portfolio. 

The next step in my [14 days of Git](https://www.techielass.com/tag/14daysofgit) learning journey is to look rewriting history! Be sure to [subscribe](https://www.techielass.com/newsletter) and join us for that step in the learning journey!

You can follow along here: [https://github.com/weeyin83/14daysofgit](https://github.com/weeyin83/14daysofgit?ref=techielass.com)