We can manipulate the History very much so. We should only ever tinker with our local history. As publicly release commits must expect to be immutable.
We use reset to unstage change, but we can also do many more different things.
- Run
source setup.sh
(or.\setup.ps1
in PowerShell)
- How does your working directory look like?
- What does your log look like? What does your stage look like?
- Try to run
git reset --soft HEAD~1
- What happens to your working directory, your log and your stage?
- Run
git reset --mixed HEAD~1
- What happens to your working directory, your log and your stage?
- Run
git reset --hard HEAD~1
- What happens to your working directory, your log and your stage?
- Now try to use
git revert HEAD~1
- What happens to your working directory, your log and your stage?
git log --oneline
git commit --amend
git status
git reset --soft
git reset --mixed
git reset --hard
git revert
The following is taken from Recap section of [https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified]. The reset command overwrites these three trees in a specific order, stopping when you tell it to:
- Move what the branch HEAD points to (stop here if --soft)
- Make the stage look like HEAD (stop here unless --hard)
- Make the working directory look like the stage