-2

Which commands will revert the change made below so that we go back to the previous checked-in state? (Select all that apply.)

given the output of git diff test.rb

$ git diff test.rb
diff --git a/test.rb b/test.rb
index ce01362..94954ab 100644
--- a/test.rb
+++ b/test.rb
@@ -1 +1,2 @@
 hello`enter code here`
+world

options are

1.git revert test.rb
2.git checkout
3.git checkout --test.rb
4.git show master:test.rb

have tried with option 1 but not working.

Jayprakash
  • 29
  • 1
  • 9

2 Answers2

1

Generate a new commit that undoes all of the changes introduced in , then apply it to the current branch.

git revert <commit>

Eg: Revert to last commit - git revert HEAD~1

Refer : Git revert and Git revert-doc

To temporarily go back to a commit & get back :

git checkout <commit>

Refer : Undo commits & Temp switch to diff commits

To stash changes made after previous commit & go back to the previous commit :

git stash
git stash clear

To remove your previous git commit :

git reset --hard [previous Commit SHA id here]
git push origin [branch Name] -f

Refer : git reset

Community
  • 1
  • 1
Ani Menon
  • 27,209
  • 16
  • 105
  • 126
0

Check git log. Copy the commit sha you to go back to and do the following

git reset --hard sha
RC_02
  • 3,146
  • 1
  • 18
  • 20