Introduction to Git
George Boorman
Curriculum Manager, DataCamp
Restoring a repo to the state prior to the previous commit
git revert
a845edcb
, ebe93178
, etcHEAD
, HEAD~1
, etcgit revert HEAD
git revert HEAD
Ctrl + O
, then Enter
Ctrl + X
[main 7d11f79] Revert "Adding fresh data for the survey."
Date: Tue Jul 30 14:17:56 2024 +0000
1 file changed, 3 deletions(-)
git revert --no-edit HEAD
git revert -n HEAD
git revert
works on commits, not individual files
To revert a single file:
git checkout
HEAD
syntax git checkout HEAD~1 -- report.md
git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: report.md
git commit -m "Checkout previous version of report.md"
[main daa6c87] Checkout previous version of report.md
1 file changed, 1 deletion(-)
git restore --staged summary_statistics.csv
git add summary_statistics.csv
git commit -m "Adding age summary statistics"
git restore --staged
Command | Result |
---|---|
git revert HEAD |
Revert all files from a given commit |
git revert HEAD --no-edit |
Revert without opening a text editor |
git revert HEAD -n |
Revert without making a new commit |
git checkout HEAD~1 -- report.md |
Revert a single file from the previous commit |
git restore --staged report.md |
Remove a single file from the staging area |
git restore --staged |
Remove all files from the staging area |
Introduction to Git