git
git
-
Git是一种版本控制软件,是一个命令,是一种工具。
-
在cmd中输入git -v查看git版本
git使用流程
- 分为三个区
- 工作区(git init)
- 暂存区(绿色 git add . )
- 版本库(git commit -m '')
常用命令
git init
: 在当前目录初始化一个新的Git仓库。git clone 源地址
: 克隆一个远程仓库到本地。git add <file>
: 将文件、文件夹添加到暂存区。git commit -m "commit message"
: 将暂存区的文件提交到本地仓库。git push 源名 源地址
: 将本地仓库的提交推送到远程仓库。git pull 源名 分支名
: 从远程仓库拉取更新到本地仓库。git status
: 查看工作区和暂存区的状态。git log
: 查看提交历史记录。git reflog
: 查看本地仓库中 HEAD 引用的变化历史。git branch
: 列出本地分支,或创建新分支。git checkout <branch-name>
: 切换到指定分支。git merge <branch-name>
: 合并指定分支到当前分支。git remote remove 源名
: 删除远程源。git remote -v
: 查看远程仓库的地址。git remote add 源名 源地址
: 添加远程源。git fetch
: 从远程仓库下载对象和引用(但不合并或修改本地分支)。git reset --hard 版本号
: 版本回退。git diff
: 查看文件之间的差异。git config --global user.email
: 设置邮箱。git config --global user.name
: 设置用户名。
git忽略文件
.gitignore
.idea *.log *.pyc __pycache__ **/migrations/*.py !**/migrations/__init__.py .venv scripts db.sqlite3 .vscode
git多分支
-
创建分支:
git branch <branch-name>
:在当前提交上创建一个新的分支。git checkout -b <branch-name>
:创建一个新的分支并立即切换到该分支。git switch -c <branch-name>
:创建一个新的分支并立即切换到该分支(Git 2.23+ 版本)。
-
切换分支:
git checkout <branch-name>
:切换到指定的分支。git switch <branch-name>
:切换到指定的分支(Git 2.23+ 版本)。
-
查看分支:
git branch
:列出本地所有分支。git branch -r
:列出远程所有分支。git branch -a
:列出所有分支(本地和远程)。
-
删除分支:
git branch -d <branch-name>
:删除本地分支(注意:删除分支前确保该分支已经合并到其他分支)。git branch -D <branch-name>
:强制删除本地分支,即使它没有被合并。git push origin --delete <branch-name>
:删除远程分支。
-
合并分支:
git merge <branch-name>
:将指定分支合并到当前分支。git rebase <branch-name>
:将当前分支的提交移动到指定分支的顶端,然后再将指定分支合并到当前分支。
-
查看分支合并历史:
git log --oneline --graph --all
:以图形化的方式查看所有分支的合并历史。
git远程仓库
设置仓库地址
git remote add origin '仓库地址'
提交
git push origin master
ssh连接操作远端
1 生成公钥和私钥
ssh-keygen -t ed25519 -C '邮箱地址'
2 在操作系统用户-家路径.ssh文件夹看到公钥和私钥
3 去gitee配置公钥
测试是否配置成功
ssh -T git@gitee.com # 输入yes
4 以后就可以免密操作
5 增加一个远程仓库地址,指定是ssh链接
git remote add origin git@gitee.com:heart99999/luffy_api.git
6 把代码推送到远端
git push origin master
补充
提交的时候遇到报错
error: failed to push some refs to 'gitee.com:heart99999/luffy_api.git'
转载至:https://blog.csdn.net/weixin_45811256/article/details/125989719
git pull --rebase origin master
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通