Git Time Travel
Changing a given commit from the past.
- Find the commit on the file that you want to change, so like
shell
git log <file>
- Once you have that commit hash, do
shell
git rebase -i <commit-hash>~1
to go back to that commit.
- Reset the changes on that commit with
shell
git reset --soft HEAD~1
- Then unstage the file on that commit with
shell
git restore --staged <name-of-file>
- Make the necessary changes, or to fully restore the file back just use
shell
git restore <name-of-file>
- Then remake the commit with
shell
git commit --amend
- Then finally
shell
git rebase --continue
to finish the interactive rebase, and
shell
git push --force
to fix up the change.