Do you want to roll back your repo to that state, or you just want your local repo to look like that?

If you reset --hard, it will make your local code and local history be just like it was at that commit. But if you wanted to push this to someone else who has the new history, it would fail:

git reset --hard c14809fa

And if you reset --soft, it will move your HEAD to where they were , but leave your local files etc. the same:

git reset --soft c14809fa

So what exactly do you want to do with this reset?

Edit -

You can add "tags" to your repo.. and then go back to a tag. But a tag is really just a shortcut to the sha1.

You can tag this as TAG1.. then a git reset --soft c14809fa, git reset --soft TAG1, or git reset --soft c14809fafb08b9e96ff2879999ba8c807d10fb07 would all do the same thing.

Answer from bwawok on Stack Overflow
Top answer
1 of 4
904

Do you want to roll back your repo to that state, or you just want your local repo to look like that?

If you reset --hard, it will make your local code and local history be just like it was at that commit. But if you wanted to push this to someone else who has the new history, it would fail:

git reset --hard c14809fa

And if you reset --soft, it will move your HEAD to where they were , but leave your local files etc. the same:

git reset --soft c14809fa

So what exactly do you want to do with this reset?

Edit -

You can add "tags" to your repo.. and then go back to a tag. But a tag is really just a shortcut to the sha1.

You can tag this as TAG1.. then a git reset --soft c14809fa, git reset --soft TAG1, or git reset --soft c14809fafb08b9e96ff2879999ba8c807d10fb07 would all do the same thing.

2 of 4
246

I think, bwawok's answer is wrong at some point:

if you do

git reset --soft c14809fa

It will make your local files changed to be like they were then, but leave your history etc. the same.

According to manual: git-reset, "git reset --soft"...

does not touch the index file nor the working tree at all (but resets the head to <commit>, just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.

So it will "remove" newer commits from the branch. This means, after looking at your old code, you cannot go to the newest commit in this branch again, easily. So it does the opposide as described by bwawok: Local files are not changed (they look exactly as before "git reset --soft"), but the history is modified (branch is truncated after the specified commit).

The command for bwawok's answer might be:

git checkout <commit>

You can use this to peek at old revision: How did my code look yesterday?

(I know, I should put this in comments to this answer, but stackoverflow does not allow me to do so! My reputation is too low.)

Discussions

How to revert back to a certain commit Id
why is this not working like I expect it to: how can I get my style sheets back? git revert “commitID” did not work More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
5
0
February 6, 2021
Can you git revert a commit without reverting recent commits?
Yes, you can revert a single commit anywhere in the history. Depending on the changes made since that commit, you may need to resolve conflicts. https://git-scm.com/docs/git-revert More on reddit.com
🌐 r/git
5
12
March 29, 2023
I'm struggling to understand how to roll back to a previous point. I want to disregard the crossed out chain completely. What am I missing here?
Edit: That was definitely it. I undid the new commit and created a new branch and it is acting as I was expecting now. I decided the last 3 commits I did were just not going to work, so I wanted to roll back to my v0.1.5a commit. So I "Undo Last Commit" a few times to get back there, then tried committing to a chain. I didn't actually create a branch, maybe that was what I did wrong? More on reddit.com
🌐 r/git
12
0
December 11, 2024
Revert a squashed merge
You can rebase or cherry-pick the old commits on top of the revert to be sure but I think it should work as is since the revert is for the squashed commits, not for the original ones. If you create a new pull request from a branch that has the old commits and the diff looks like expected it will be fine. If the diff is empty, try the rebase or cherry-pick approach. More on reddit.com
🌐 r/git
12
1
June 6, 2024
🌐
Codefinity
codefinity.com › courses › v2 › 7533d91f-0a23-44a3-afc7-c84d5072e189 › b9a4a4e8-3d95-4d5d-bf29-f87c3fd673a4 › c3bcd665-926a-44bf-adf1-d1f97167d536
Learn Reverting a Specific Commit | Undoing Changes
Basic syntax: ... Instead of using HEAD (which targets the latest commit), specify the hash of the commit (commit ID) you want to revert by replacing <commit-hash> with the actual hash value.
🌐
TheServerSide
theserverside.com › tutorial › How-to-git-revert-a-commit-A-simple-undo-changes-example
How to revert a Git commit: A simple example | TheServerSide
In review, the steps to git revert a commit and undo unwanted changes are the following: Locate the ID of the commit to revert with the git log or reflog command.
🌐
Devart
devart.com › dbforge › sql › source-control › reverting-git-commit-with-examples.html
Reverting a Git Commit with Examples - Devart
In Database Explorer, right-click ... the History document, copy the Revision ID. Run the Command Prompt and type git revert and the commit ID you want to undo, and then press Enter....
🌐
LinkedIn
linkedin.com › pulse › master-git-revert-code-from-any-branch-using-commit-id-akash-gadhiya-mcgtf
Master Git: Revert Code from Any Branch Using Commit ID - Step-by-Step Guide
January 16, 2024 - Execute the revert command:Use the git revert command, followed by the commit ID: git revert <commit_id>This creates a new commit that undoes the changes introduced by the specified commit.
🌐
GitKraken
gitkraken.com › home › learn › problems & solutions › how to revert a git commit
Git Revert Commit | Solutions to Git Problems
February 5, 2024 - This will show you a list of your commits along with each commit’s unique ID. Next, copy the commit ID of the commit you want to revert. Now run git revert <commit ID>. This creates a new commit that negates the commit you specified.
Find elsewhere
🌐
Git
git-scm.com › docs › git-revert.html
Git - git-revert Documentation
This is useful when reverting more than one commits' effect to your index in a row. ... GPG-sign commits. The keyid argument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space.
🌐
Linux Hint
linuxhint.com › reverting-to-specific-commit-based-commit-id-with-git
Reverting to a Specific Commit Based on Commit id with Git – Linux Hint
To revert to a specific commit by using the commit id, first, open the Git repository. Next, make some changes and commit them using the “$ git commit” command. After that, to revert changes or move back to a specific commit, utilize the “$ git reset –hard <commit-id>” command.
🌐
TechTarget
techtarget.com › searchitoperations › answer › How-to-roll-back-Git-code-to-a-previous-commit
How to roll back Git code to a previous commit | TechTarget
The code 3a96a8e represents the commit ID, gained from the git log output in Figure 1. Figure 2. The code displays the commit ID 3a96a8e that will execute the revert.
🌐
Built In
builtin.com › articles › git-revert-a-file
Git Revert a File: A Guide | Built In
Find the path to the file you want to revert from the working directory. In the terminal, change directories to the working directory. Type git checkout [commit ID] -- path/to/file and hit enter.
🌐
freeCodeCamp
forum.freecodecamp.org › t › how-to-revert-back-to-a-certain-commit-id › 444698
How to revert back to a certain commit Id - The freeCodeCamp Forum
why is this not working like I expect it to: how can I get my style sheets back? git revert “commitID” did not work
Published   February 6, 2021
🌐
freeCodeCamp
freecodecamp.org › news › git-reverting-to-previous-commit-how-to-revert-to-last-commit
Git Reverting to Previous Commit – How to Revert to Last Commit
October 19, 2022 - To do that, run the command below: ... As you can see above, this command lists all your commits along with their IDs. To go back to the second commit, you run the git reset command followed by the commit ID.
🌐
Softpost
softpost.org › git › how-to-revert-last-commit-in-git
Revert commit in git
git revert <commit-id> git revert 7893dd38bd467d git revert HEAD git revert HEAD^ Below example will help you understand how Git revert works. Notice that even though we revert second last commit – Q, other commits R and S are still in the git log history and additional commit T is also created ...
🌐
Davidvarghese
notes.davidvarghese.net › software-engineering › devops › git › commands › git-revert-and-reset-command
Git Revert & Reset Command - Digital Archive - David Varghese
January 28, 2024 - # Delete multiple commit and go back in time # The files from the deleted commits will show as upstaged git reset --mixed <commit-id> # Delete commits and the changes to the files git reset --hard <commit-id> # Delete commits and modified files ...
🌐
Graphite
graphite.com › guides › revert-to-previous-commit-git
How to revert to a previous commit in Git - Graphite
To revert the entire repository to the state of a previous commit, use: ... Replace <commit-id> with the ID of the commit you're reverting to.
🌐
Scaler
scaler.com › home › topics › git › how to revert last git commit?
How To Revert Last Git Commit? - Scaler Topics
March 9, 2023 - The Git revert command with commit id is used to revert and roll back a specific commit identified by its commit id.
🌐
DataCamp
datacamp.com › tutorial › git-reset-revert-tutorial
Git Reset and Revert Tutorial for Beginners | DataCamp
December 16, 2022 - From the log, we can notice that a new commit has been created with the ID c61ef6b4e86f41f47c8c77de3b5fca3945a7c075 to reverse the original commit with the ID eae84e7669af733ee6c1b854f2fcd9acfea9d4a3. In this example, since we have a single commit, we could use git revert HEAD, which has the ...