工作区→暂存区→版本库
设置用户名、邮箱
git config --global user.name xxx : 设置全局用户名, 信息记录在~/.gitconfig 文件中
git config --global user.email xxx@xxx.com : 设置全局邮箱地址, 信息记录在~/.gitconfig 文件中
配置成git仓库
git init : 将当前目录配置成git仓库, 信息记录在隐藏的.git文件中
常用命令
git add xxx : 将xx文件添加到暂存区
git add . : 将所有待加入暂存区的文件加入暂存区
git commit -m "备注信息" : 将暂存区的内容提交到当前分支
git status : 查看仓库状态
git diff xxx : 查看xx文件相对于暂存区修改了哪些内容
git diff HEAD : 查看与最新提交的差别
删除命令
git rm --cached xx : 将文件从仓库索引目录中删掉, 不管理了
git restore --staged xx : 将xx从暂存区里移除, 管理
git restore xx 或 git checkout - xx : 将xx文件的修改撤销(未加入暂存区)
查看命令
git log : 查看当前分支的所有版本
git log --pretty=oneline : 用一行来显示
git reflog : 查看HEAD指针的移动历史(包括被回滚的版本)
git log --graph : 以图标形式查看分支
git branch -a : 同时查看本地和远程仓库分支信息
代码回滚
git reset --hard HEAD^ 或 git reset --hard HEAD~ : 将代码回滚到上一个版本
git reset --hard HEAD^^ : 往上回滚两次, 以此类推
git reset --hard HEAD~100 : 回滚100个版本
git reset --hard 版本号 : 回滚到某一特定版本
远程仓库
git remote add origin git@git.acwing.com:xxx/XXX.git : 将本地仓库关联远程仓库
git push -u(第一次需要-u以后不需要) : 将当前分支推送到远程仓库
git push origin branch_name : 将本地的某个分支推送到远程仓库
git clone git@git.acwing.com:/xxx/XXX.git : 将远程仓库XXX下载到当前目录下
git push --set-upstream origin branch_name : 设置本地的 branch_name 分支对应远程仓库的 branch_name 分支(上传分支)
git push -d origin branch_name : 删除远程仓库的 branch_name 分支
git branch --set-upstream-to=origin/branch_name1 branch_name2 : 将远程的 branch_name1 分支与本地的 branch_name2 分支对应
git pull : 将远程仓库的当前分支与本地仓库的当前分支合并
git pull origin branch_name : 将远程仓库的 branch_name 分支与本地仓库的当前分支合并
git checkout -t origin/branch_name : 将远程的 branch_name 分支拉取到本地
分支命令
git branch branch_name : 创建新分支
git branch : 查看所有分支和当前分支
git checkout -b branch_name : 创建并切换到 branch_name 这个分支
git checkout branch_name : 切换到 branch_name 这个分支
git merge branch_name : 将分支 branch_name 合并到当前分支上
git branch -d branch_name : 删除本地仓库的 branch_name 分支
stash暂存
git stash : 将工作区和暂存区中未提交的修改存入栈中
git stash list : 查看栈中所有元素
git stash pop : 将栈顶存储的修改恢复到当前分支, 同时删除栈顶元素
git stash drop: 删除栈顶存储的修改
git stash apply: 将栈顶存储的修改恢复到当前分支, 但不删除栈顶元素
posted @
2023-08-06 10:04
LH寒酥
阅读(
24)
评论()
收藏
举报