常用 git 命令
本地分支强制与远程分支同步
有时候本地搞混乱了,想要从远程分支拉取进行同步覆盖, 可以执行下面命令:
# devop-branch是远程的分支名. 执行前可以先备份本地分支.
git reset --hard origin/devop-branch
https://www.educative.io/answers/how-to-reset-a-git-branch-to-a-remote-repository
回滚上一次commit
https://www.git-tower.com/learn/git/faq/undo-last-commit
本地保留变更
git reset --soft HEAD~1
本地删除变更
git reset --soft HEAD~1
回滚 git add
https://stackoverflow.com/questions/348170/how-do-i-undo-git-add-before-commit
To unstage all changes for all files:
git reset
Undo git add for uncommitted changes with:
git reset <file>
That will remove the file from the current index (the "about to be committed" list) without changing anything else.