Git Reference
Git Reference Originally published in Chinese on 2022-03-31; this English edition preserves the original scope and technical context. HEAD Usage HEAD represents the last commit. HEAD^ represents the second-to-last commit from the end. HEAD^^ represents the third-to-last commit from the end, and so on. HEAD~0 represents the last commit. HEAD~1 represents the second-to-last commit from the end, and so on. Returning to a Previous Commit git reflog # Records each update of the local branch in the repository git reset HEAD@{index} # Returns to a previous commit, leaving changes in the working directory git reset hash --hard # Adds --hard to ignore all changes to files Add Some Modifications Based on the Last Commit git add . # Adds modifications to the staging area. git commit --amend # git commit --amend --no-edit # add --no-edit If the last commit has been pushed to the remote, pushing again requires adding the -f flag. ...