0

While using git hub I wanted to delete/undo a comment that I had recently posted. But I was unable to do it. So I want to know how to undo the recent comment in git.

2 Answers2

0

Here is one of the several and easiest way to do it.

  1. First of all lets check commit history.
git log --oneline
  1. Now in the output you will see a list of commits. Something like shown below.
241b8e7 (HEAD -> papers) Added paper-logic according to new requirements
8ae8f7d paper backend fixed
3c9a3ce toggle sidebar change added
af1af34 link to style tag added
  1. Now as per your question you want to undo previous commit i.e you want your project to be at 2nd last commit.

    So "code"(left of commit statement- "paper backend fixed" ) for 2nd last commit from the above example is 8ae8f7d. Copy this code.

  2. To go to that commit enter the following in terminal.
    git reset --hard <code>

What this will do is forcefully change all your project to the stage as it was on mentioned commit.
Note that it is irreversible i.e once you have gone to previous commit you cannot come to commits above it

RUGVED
  • 174
  • 3
  • 3
0

You need to undo the commit as well.

Undo Last Git Commit with reset

$ git reset --soft HEAD~1

If you are not familiar with this notation, “HEAD~1” “HEAD~1” means that you want to reset the HEAD (the last commit) to one commit before in the log history.

You can use this as well

$ git reset --hard <commit sha1 | reference>
$ git push --force

to check the commit hash and reference you can use

$ git log --oneline

or

$ git log

Undo Last Git Commit with revert

$ git log
$ git revert <commit sha1 | reference>
$ git push --force

You might want to check these as well How do I undo the most recent local commits in Git?