# Step 1: Checkout files from 8 commits ago
git checkout HEAD~8 -- .
# Step 2: Verify changes
git status
# Step 3: Stage and commit the reverted state
git add .
git commit -m "Rollback to state from 8 commits ago"
# Step 4: (Optional) Reset working directory to clean state
git reset --hard HEAD
I need to also explain how to change history of commits, to fix dates and authors
; git checkout \(@;
; How to use REBASE ?
; git rebase -i HEAD~11
; A="01-16-2023 21:17:11 +0100"; LC_ALL=C GIT_COMMITTER_DATE=\)A git ca –date $A ; Don’t make me the author on rebase, keep the blame on them bro 🤙 git -c rebase.instructionFormat='%s%nexec GIT_COMMITTER_DATE="%cD" git commit --amend --no-edit' rebase -i
To check out a specific file from a particular commit in Git, you can use the following command:
git checkout 5c63502 -- path/to/your/file
Here’s a breakdown of the command:
git checkout
: This is the command used to switch branches or restore working tree files.5c63502
: This is the commit hash from which you want to check out the file.--
: This separates the commit hash from the file path, ensuring that Git interprets the following argument as a file path.path/to/your/file
: This is the path to the specific file you want to check out from the commit.
For example, if you want to check out a file named example.txt
from the commit 5c63502
, you would run:
git checkout 5c63502 -- example.txt
This will replace the current version of example.txt
in your working directory with the version from the commit 5c63502
.
If you want to check out multiple files from the same commit, you can specify them one after the other:
git checkout 5c63502 -- file1.txt file2.txt file3.txt
This command will check out file1.txt
, file2.txt
, and file3.txt
from the commit 5c63502
.
Remember that this operation will overwrite the current state of the specified files in your working directory, so make sure you have any important changes committed or stashed before running the command.