git-常用基础指令

一、基本指令

1. 配置用户名和邮箱
git 复制代码
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"
2. 初始化仓库
git 复制代码
git init
3. 克隆仓库
git 复制代码
git clone <repository_url>
4. 查看当前状态
git 复制代码
git status
5. 添加文件到暂存区
git 复制代码
git add <file_name>
      # 添加所有文件
git add .
6. 提交更改
git 复制代码
git commit -m "Commit message"

二、分支管理

1. 查看分支
git 复制代码
git branch
2. 创建新分支
git 复制代码
git branch <branch_name>
3. 切换分支
git 复制代码
git checkout <branch_name>
4. 创建并切换到新分支
git 复制代码
git checkout -b <branch_name>
5. 删除分支
git 复制代码
git branch -d <branch_name>

三、合并与重置

1. 合并分支
git 复制代码
git merge <branch_name>
2. 解决合并冲突
复制代码
  手动解决文件中的冲突后,添加解决冲突的文件并提交:
git 复制代码
git add <conflicted_file>
git commit -m "Resolved merge conflict"
3. 重置到某个提交
git 复制代码
git reset --hard <commit_id>

四、远程仓库

1. 查看远程仓库
git 复制代码
git remote -v
2. 添加远程仓库
git 复制代码
git remote add origin <repository_url>
3. 推送代码到远程仓库
git 复制代码
git push origin <branch_name>
4. 拉取远程仓库的代码
git 复制代码
git pull origin <branch_name>

五、查看日志

1. 查看提交历史
git 复制代码
git log
2. 查看简洁的提交历史
git 复制代码
git log --oneline

六、比较差异

1. 查看工作区与暂存区的差异
git 复制代码
git diff
2. 查看暂存区与最后一次提交的差异
git 复制代码
git diff --cached
3. 查看最近一次Git提交的增删行数信息:
sh 复制代码
git diff --stat HEAD~1 HEAD

七、其他使用详见本专栏

相关推荐
火车叼位12 分钟前
Git 历史清理实践:彻底移除误提交的 node_modules
git
火车叼位14 分钟前
用git filter-repo轻松清理Git仓库历史的详细教程
git
Lily55_Li2 小时前
Git标准化开发流程
git
江城月下2 小时前
Git 版本控制核心流程与协作指南(从入门到冲突解决)
git
Revol_C4 小时前
【Git 操作笔记】第1期--云代码仓库更换服务商,本地如何批量更新对应项目的git地址(持续更新...)
前端·git
猫头虎5 小时前
开源协议区别与限制详解:Fork、改名、再发布是否合法?(MIT、Apache、GPL、BSD、SSPL、BSL)
git·开源·github·apache·开源软件·开源协议·gitcode
Kiri霧15 小时前
Git入门
git
Nejosi_念旧16 小时前
git报错解决:ssh: connect to host github.com port 22: Connection refused
git·ssh·github
你的人类朋友16 小时前
说说git的变基
前端·git·后端
程序设计实验室17 小时前
在Windows上将git与ssh-agent搭配使用,再也不用输入git密码了
windows·git