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 workspacegit 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 unchangedgit reset --hard reset HEAD, staging area, workspace as last commitgit reset <file-name> reset the specified file in the staging area; the workspace remains unchangedgit update-ref -d HEAD which puts all changes back into the workspace and clears all commits, so that the first commit can be recommittedgit diff --name-only --diff-filter=U show the list of conflicting files in the workspacegit 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 commitgit 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 wipedgit 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 wipedgit revert -n <commit-id> Create a new commit to undo the specified commit, keeping the commits after the target commitgit clean [-f|d|x] -n Show the files that will be deletedgit clean Delete untracked files from the workspacegit clean -d Remove untracked folders from the workspacegit clean -f [path] Force deletiongit clean -X -f Remove files ignored by .gitignore settinggit reset --hard
git clean -df
git fetch --all && git reset --hard origin/master
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
git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d