How to undo a public commit

If we execute git revert HEAD, Git will create a new commit with the inverse of the last commit.

git revert <COMMIT_ID>

delete file from repo

remove from repo and local

git rm file1.txt
git commit -m "remove file1.txt"

remove the file only from the Git repository and not remove it from the filesystem:

git rm --cached file1.txt
git commit -m "remove file1.txt"

undo git add before commit with

git reset <file>

remove untracked files

$ git reset --hard HEAD
$ git clean -fd

查看某个文件的commit历史

git log --follow -p <filename>

查看贡献者列表与commit次数

git shortlog -sn

删除远端分支

git push origin :<branch_name>
OR
git push origin --delete <branch_name>

修改commit

git rebase -i HEAD~2

撤销commit

git reset HEAD~1
or
git reset <commit_id>