Git笔记
创建Git仓库:
cd dir
git init
将文件添加到暂存区
git add file
将文件修改提交到版本库
git commit -m "说明" //说明一般是必须的
版本库更新流程
st=>start: 工作区(文件夹内)
operation1=>operation: add
operationmid=>inputoutput: 暂存区
operation2=>opertation: commit
e=>end: 版本库
st->operation1->operationmid->operation2->e
撤销
git checkout -- <file>
//回退文件在本区域内的初始状态,如暂暂存区作出修改则撤销在暂存区内的修改,在工作区则撤销工作区内做的修改
//注意:git checkout <branch>为切换分支命令
恢复上一版本
git reset HEAD <file>
//如果add则清除add并回退最新版本,没有add则直接回退最新版本
查看历史记录
git log [--graph]
查看当前仓库状态
git status
回退版本库版本
git reset --hard HEAD^[^^^]
//多少个^就回退多少个版本,如果太多的话就用HEAD~[num]
添加远程版本库
git remote add [origin/远程库名称] [git]
git push -u [远程库名称] [本地分支名称]
//首次push添加 -u 参数,之后就不用了