How to turn back time on your repo
git add and stop tracking filesgit commitgit add <filename> to track themgit add <filename>, but not yet committedgit commit -m "message here" and are associated with a unique git commit idWe may have created or edited files, but not have used git add or git commit yet…
rm filename, or right click on them and deleteAll our other examples assume that at some point, the file has been tracked with git…
If you’ve modified a file but haven’t run git add yet:
Warning
This permanently deletes your changes!
If we do a git add command to a file, we “stage” the file…
If we do a git add command to a file, we “stage” the file…
If you’ve run git add but haven’t committed yet:
This moves the file back to “modified” state - your changes are still there!
git restore command we did for untracked files!This moves the file back to “modified”/“unstaged” state - your changes are still there!
A git restore --staged command will undo an add
A git commit saves a snapshot of our folder
Lots of different options:
Undo the previous commit, but keep the changes in our working directory to sort through
Rewind time to a specific old commit (and create a new branch to keep working from)
git log --oneline gives us a easy-to-read snippet of our commit historyHEAD tells you where you are in the git map
git reset --soft HEAD~1: moves commit back to the staging area
git added, but not git committedgit reset HEAD~1: moves files back to the working directory
git added or git committedgit status to make sure you’ve got a clean working directorygit log --oneline to find the commit you want to swap to
git branch new-branch-name abc1234 where abc1234 is your chosen git idgit switch new-branch-namegit switch -c new-branch-name abc1234