Soft reset - resets to the previous state, but leaves your changes

git reset --soft UniqueHash

Hard reset - resets everything to the previous state, deletes your changes

git reset --hard UniqueHash

Amend commit - saves changes to the same previous commit

git commit --amend

Exercise: fixing commit

  1. Create new Git repository
    git init
  2. Create a new file index.html with content "Hello Wrold!"
    touch index.html
    vi index.html
  3. Add and Commit index.html file with message "Initial commit"
    git add index.html
    git commit -m "Initial commit"
  4. Check git status (see: On branch master nothing to commit, working directory clean)
    git status
  5. Check git log (see:Initial commit)
    git log --oneline
  6. Open index.html and change text to "Hello World!"
    vi index.html
  7. Add and Commit index.html file with message "Fix typo"
    git add index.html
    git commit -m "Fix typo"
  8. Check git log (see: both commits)
    git log --oneline

Exercise: amending commit

  1. Check git log and copy UniqueHash from Initial commit
    git log --oneline
  2. Hard reset repository to the initial commit
    git reset --hard UniqueHash
  3. Review index.html and check that the typo is there
    cat index.html
  4. Open index.html and change text to "Hello World!"
    vi index.html
  5. Add index.html to the staging area
    git add index.html
  6. Check git status (see: Changes to be committed: modified: index.html)
    git status
  7. Amend commit
    git commit --amend
  8. Check git log (see: only initial commit)
    git log --oneline
  9. Review index.html and check that the typo is fixed
    cat index.html