git 常见命令

基础操作

bash 复制代码
# 添加文件到暂存区
git add <filename>        # 添加特定文件
$ git add 3.txt

git add .                 # 添加所有文件


# 提交更改
git commit -m "提交信息"

$ git commit -m "修改2.txt"


# 查看远程仓库
git remote -v

$ git remote -v
origin  https://gitee.com/shenpengcheng030415/git01.git (fetch)
origin  https://gitee.com/shenpengcheng030415/git01.git (push)


# 添加远程仓库
git remote add origin <url>

$ git remote add origin https://gitee.com/shenpengcheng030415/git01.git


# 推送到远程仓库
git push origin <branch_name>

$ git push origin master


# 从远程拉取
git pull origin <branch_name>

$ git pull origin master

分支

bash 复制代码
# 查看分支
git branch               # 本地分支

$ git branch
* master



git branch -a            # 所有分支(包括远程)

$ git branch -a
* master
  remotes/origin/master


# 创建分支
git branch <branch_name>

$ git branch b1



# 切换分支
git checkout <branch_name>

$ git checkout b1
Switched to branch 'b1'


git switch <branch_name>  # 新版本推荐


$ git switch master
Switched to branch 'master'



# 创建并切换分支
git checkout -b <branch_name> <tag_name>

git checkout -b fix-v1.0 v1.0
# 会创建一个名为 fix-v1.0 的新分支,且该分支的初始状态完全等同于 v1.0 标签对应的提交(包含当时的所有文件和代码)。后续在这个分支上的修改,会基于 v1.0 的状态进行,不会影响原标签或其他分支。

git switch -c <branch_name>



# 合并分支 (是将指定分支的代码合并到当前分支)
git merge <branch_name>

$ git merge b1



# 删除分支
git branch -d <branch_name>



$ git branch -d b2

标签

相关推荐
深海鱼在掘金3 天前
Git 完全指南 —— 第1章:Git 概览与版本控制演进
git
noravinsc3 天前
关于Git Flow
git
蜜獾云3 天前
在Git中配置用户名和密码
git
scx_link3 天前
通过git bash在本地创建分支,并推送到远程仓库中
开发语言·git·bash
南大白3 天前
IntelliJ IDEA 运行时的 JVM 本地内存溢出崩溃
git
码农小旋风4 天前
Claude Code 基础用法大全:对话、分析、修改、测试、Git 和工作流
人工智能·git·chatgpt·claude
南大白4 天前
Git 撤回提交完整方案
git
像风一样的男人@4 天前
python --实现代理服务器
git·ui
sbjdhjd4 天前
从零搭建企业级 CI/CD(下):Jenkins+GitLab+Harbor 全链路实战指南
git·servlet·ci/cd·云原生·云计算·gitlab·jenkins
码云数智-大飞4 天前
Go Channel 详解:并发通信的正确姿势
前端·数据库·git