- 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 NAME | COMMIT MESSAGE | |
1 | file-A | file-A-commit |
2 | file-B | file-B-commit |
3 | file-C | file-C-commit |
(ii) Let’s add one more file with commit and will see logs
FILE NAME | COMMIT MESSAGE | |
4 | file-D | file-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> |