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

标签

相关推荐
ruanCat19 分钟前
前端工程化工具链从零配置:simple-git-hooks + lint-staged + commitlint
前端·git·代码规范
木子小喵2 小时前
Git的使用介绍!超通俗!
git
coderYYY2 小时前
git push报错Authentication failed for ‘xxx’也不会弹要求输入用户名密码的最终解决方法
前端·git·gitee·github
@PHARAOH2 小时前
WHAT - git worktree 开发的并发模型
大数据·git·elasticsearch
苦瓜小生4 小时前
【Git】| 将拉下来的代码上传到自己的 Gitee 仓库(手把手教学)
git·gitee
WKP94184 小时前
git的merge和rebase操作
git
___波子 Pro Max.7 小时前
Git 分支切换
git
win x7 小时前
一篇搞懂Git基础操作
linux·git
一个有温度的技术博主8 小时前
网安实验系列五:.git源代码泄露
git
吴声子夜歌8 小时前
TypeScript——索引类型、映射对象类型、条件类型
git·ubuntu·typescript