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

标签

相关推荐
AIMath~5 小时前
Git 子模块(Submodule)目录结构清除实战复盘
git
切糕师学AI5 小时前
Ubuntu 下 Git 完全使用指南
linux·git·ubuntu
一袋米扛几楼987 小时前
【Git】规范化协作:详解 GitHub 工作流中的 Issue、Branch 与 Pull Request 最佳实践
前端·git·github·issue
尘埃落定wf8 小时前
# GitHub CLI:告别繁琐的 Git 命令,让开发更高效
git·github
恋喵大鲤鱼8 小时前
git clone
git·git clone
金牛IT10 小时前
Gogs 轻量级 Git 服务器搭建与使用
运维·服务器·git
Qres82120 小时前
Git安装记录
git
wj3055853781 天前
Codex + Git 开发环境配置指南(WSL版)
linux·运维·git
楠枬1 天前
Git 分支管理
git
奇怪的点1 天前
git clone失败
git