• git checkout . Restore all staging area files to the workspace (used to undo all changes in the workspace)
  • git checkout <file-name> Restore staging area files to the workspace (used to undo changes made to files in the workspace)
  • git checkout <commit-id> <file-name> Restore a committed file to the staging area and to the workspace
  • git reset [--mixed | soft | hard | merge | keep ]
    --mixed (default mode) only resets the staging area and points HEAD to the commit, but does not reset the workspace, local file changes are not affected. (fallback to a version, keep source only, fallback commit and index information)
    No changes are made to the contents of the --soft workspace, HEAD points to commit and all changes since commit are rolled back to the 'staging area'. (The fallback to a particular version is only the commit information. If you want to commit again, just commit.)
    --hard Resets the staging area and workspace so that any changes made in the workspace since commit are discarded and HEAD is pointed to commit. (A complete fallback to a version is made and the local source code is changed to the previous version.)
    --keep Keeps the part of the difference between the workspace and HEAD, the command will fail if there is a conflict between the fallback and the retained changes (there are identical files). (Not commonly used)
    --merge Preserve the difference between the staging area and the workspace. The command will fail if there is a conflict (with the same file) between the rewind and the retained changes. (not commonly used)
    
  • git reset reset HEAD, keeping the staging area the same as the last commit; but leaving the workspace unchanged
  • ``git reset –soft` Reset HEAD to match the last commit; staging and workspace remain unchanged
  • git reset --hard reset HEAD, staging area, workspace as last commit
  • git reset <file-name> reset the specified file in the staging area; the workspace remains unchanged
  • git update-ref -d HEAD which puts all changes back into the workspace and clears all commits, so that the first commit can be recommitted
  • git diff --name-only --diff-filter=U show the list of conflicting files in the workspace
  • git reset <commit-id> reset the pointer to the current branch to the specified commit, and reset the staging area, but leave the workspace unchanged, and erase any commits after the specified commit
  • git reset --soft <commit-id> Reset the HEAD of the current branch to the specified commit, with the staging area and workspace unchanged, and any commits after the specified commit will be wiped
  • git reset --hard <commit-id> Reset the HEAD of the current branch to the specified commit, and reset the staging area and workspace to match the specified commit, and any commits after the specified commit will be wiped
  • git revert -n <commit-id> Create a new commit to undo the specified commit, keeping the commits after the target commit
  • git clean [-f|d|x] -n Show the files that will be deleted
  • git clean Delete untracked files from the workspace
  • git clean -d Remove untracked folders from the workspace
  • git clean -f [path] Force deletion
  • git clean -X -f Remove files ignored by .gitignore setting
  • Revert to the most recent commit
    git reset --hard
    git clean -df
    
  • Discard all local changes and go back to the remote repository
    git fetch --all && git reset --hard origin/master
    
  • Roll back the remote code
    git log #View branch commit history, identify commits that need to be rolled back
    git reset --hard 551c2aa #Roll back commits
    git push -f origin master #Push to the remote branch
    git push -f origin master
    
  • Delete a branch that has been merged to master
    git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d