Undo git Add Operation
git reset HEAD <file> # 取消add操作并保留修改-- <file> #若继续该命令,则会删除掉刚刚的修改内容
Undo Git commit Operation
reset --soft <commit_id> #可以回退到某个commit并保存之前的修改 <commit_id>从git log中取,取前7位即可reset --hard <commit_id> #回退到某个commit不保留之前的修改
Undo the commit after you revoke the GIT push action push
<commit_id>
Principle: Git revert will produce a new commit, which is the opposite (or reverse) of the commit that corresponds to the specified SHA. Any content deleted from the original commit will be added back in the new commit, and any content added to the original commit will be deleted in the new commit. This is the safest and most basic undo scenario for Git, because it doesn't change history-so you can now git push a new "invert" commit to offset the commit you mistakenly committed.
Delete some files that should not be submitted after push delete the file on the remote branch, and also delete the files from the local repository:
file"test delete" name
Delete files on the remote branch, but also keep the files for the local repository
--cached filename commit -m "delete" git push origin branch name
Delete a folder on a remote branch, but also keep the folders and files for the local warehouse
--cached directorycommit -m "test"git push origin branch name
Reference
git revokes the commit and saves the previous changes
How to undo (almost) any action in Git
git various undo operations