基础指令
查看状态,查看 git 工作区
git status
添加文件到待确认
git add <file..> # add some files
git add . # add all files
确认提交
git commit
撤销某几个提交
git reset --soft HEAD~1 # reset the lastest one commit
版本控制
添加分支,分支目录 feature,分支名字为 shop
git -b feature/shop
已经提交了,怎么恢复久的版本?
已经提交并且 push 到远端,怎么恢复旧的版本?
-
强制 reset 到旧版本
# reset to lastest version, reset to the commit before head. git reset --hard HEAD~1 # or write the version id explicitly. git reset --hard <sha1-commit-id>
-
强制 push 到远端仓库,回退版本才生效。
git push origin HEAD --force
-
然而,最好是新建分支来回退旧版本。否则,别人在此时拉去分支会把旧版本拉到他的本地。
git checkout -b <new-branch-name> <sha1-commit-id>