SAGARFIVE

1. Introduction

2. Git Basics

3.  Git Terminology

4.  Git Branching

5.  Git - Github

6.  Git Add (Git staging)

7.  Git Commit

8.  Github Advanced

9.  Git Remote

7.11 Git revert (Revert the file changes with new commit)

  • In Git, the term revert is used to revert some changes.
  • The git revert command is used to apply revert operation.
  • it will create a new change with the opposite effect and thereby undo the specific commit.
  • Generally, git revert is a commit.

(i) Created 3 files with 3 commits as below

FILE  NAMECOMMIT MESSAGE
1file-Afile-A-commit
2file-Bfile-B-commit
3file-Cfile-C-commit



(ii) Let’s add one more file with commit and will see logs

FILE  NAMECOMMIT MESSAGE
4file-Dfile-D-commit

(iii) Now we need to rollback,

With some reason we don’t need the changes made by commit file-commit-D-1

So here reverting to file-C-commit

git revert <commit-hash-to-revert>

Observations :

  • It added a new commit with changes
  • Changes shows that file-C deleted at working directory
  • Means it will revert to that commit stage without that committed files(it removes the files which committed by that specific commit)
  • Insteading of moving back to old commit , it will create a new commit
  • So in real time it will not delete any files from the any commit

Reset(if we need the files back) :

git reset <commit-hash>