git命令总结
添加远端仓库,命令 git remote add <远端名称> <仓库路径>
·远端名称,默认是origin,取决于远端服务器设置
·仓库路径,从远端服务器获取URL
1 | git remote add origin git@gitee.com:ss /git_test .gitgit |
将本地分支与远端分支关联关系,--set-upstream
1 | git push -- set -upstream origin master:master |
1 | git push origin master |
创建新的分支
1 2 | #创建新的分支xx git checkout -b xx |
查看所有分支
1 | git branch -a |
切换到指定分支
1 2 | #切换到xx分支 git checkout xx |
删除分支
1 | git branch -d online是 |
删除远端分支
1 | git push origin --delete remoteBranchName |
将远程仓库克隆岛本地git_test02目录下
1 | git clone git@gitee.com/**/*.git git_test02以 |
查看日志:用于查看提交记录
命令形式:git log [option]
·--all 显示所有分支
· --pretty=online 将提交信息显示为一行
· --abbrev-commit 是的输出的commitId更简单
· --graph 以图的形式显示
以精简方式显示提交记录
1 | git-log |
从远程仓库拉取命令:git pull [remote name] [branch name]
·拉取指令是将远端仓库的修改拉到本地并自动合并
·如果不指定远端名称和分支名则抓取所有并更亲当前分支
查看历史
添加别名
1 2 | #用于输出git提交日志 alias git-log= 'git log --pretty=oneline --all --graph --abbrev-commit' |
回退到某一个版本
1 | git reset --hard commitID |
取消回退的版本,查看之前的记录
1 | git reflog |
分支操作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #查看分支<br>git branch<br><br>#创建分支 git branch dev01 #切换分支 git checkout dev01 #创建并切换分支 git checkout -b dev01 #删除分支 git branch -d dev01 #合并分支 [master] git merge dev01<br><br> |
git查看配置信息以及设置配置信息
1 2 3 4 5 6 7 8 9 10 11 12 | 查看系统配置信息 git config --system --list #查看当前用户配置信息 git config --global --list #查看当前仓库配置信息 git config -- local --list #设置用户信息 git config --global user.name "hhh" git config --global user.email "dddd@163.com" |
推送到远端仓库并且同时建立与远端分支的联系,后续只用push就可以
1 2 | -- set -upstream git push -- set -upstream orgin master:master |
查看本地仓库与远端仓库的对应关系
1 | git branch -vv |
查看远程仓库,查看有没有添加上远端
1 | git remote |
从远端克隆仓库
1 2 | #克隆gxxx.git仓库,并将文件夹重命名为git11 git clone git@gitee.com /gxxx .git git11 |
利用credentials进行https的提交、拉取认证
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #配置credential helper #创建文件.git-credentials touch ~/.git-credentials vim ~/.git-credentials #输入配置信息,并保存退出 https: // {username}:{password}@gitee.com/ #在用户目录下执行 cd ~ git config --global credential.helper store #查看~/.gitconfig文件,多一项[credential] helper=store cat ~/.gitconfig |
修改最近一条已经提交的commit记录,但是还没有push到远端
1 | git commit --amend |
修改提交记录后保存,退出
git修改远端分支名称
1 2 3 4 5 6 7 8 9 10 11 | 1. #本地分支重命名 git branch -m oldBranch newBranch 2. #删除远端分支 git push --delete origin oldBranch 3. #重命名后的分支推到远端 git push origin newBranch 4. #修改后的本地分支与远端分支关联 git branch -- set -upstream-to origin /newBranch |
git 合并commit记录
1 2 3 4 5 | # 合并多条commit,commitid是要合并的的id的上一次提交记录的id git rebase -i commid #提交到远端,只能在自己的分支上 git push -f |
git 官方命令帮助文档
1 | https://docs.github.com/zh/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律