Git常用命令

Git 是一个功能强大的版本控制系统,常用于跟踪代码的变化和管理软件开发的历史记录。以下是一些常用的 Git 命令:

配置 Git

bash 复制代码
git config --global user.name "你的名字"
git config --global user.email "你的邮箱"

初始化仓库

bash 复制代码
git init

克隆仓库

bash 复制代码
git clone <仓库地址>

查看状态

bash 复制代码
git status

添加文件到暂存区

bash 复制代码
git add <文件名或路径>

提交更改

bash 复制代码
git commit -m "提交信息"

推送至远程仓库

bash 复制代码
git push origin <分支名>

拉取远程仓库更新

bash 复制代码
git pull origin <分支名>

查看提交历史

bash 复制代码
git log

查看分支

bash 复制代码
git branch

创建新分支

bash 复制代码
git branch <新分支名>

切换分支

bash 复制代码
git checkout <分支名>

创建并切换到新分支

bash 复制代码
git checkout -b <新分支名>

合并分支

bash 复制代码
git merge <要合并的分支名>

解决冲突

  1. 打开冲突的文件,手动解决冲突后保存。
  2. 使用 git add <文件名> 标记冲突已解决。
  3. 执行 git commit 提交解决冲突后的结果。

撤销工作区的修改

bash 复制代码
git checkout -- <文件名>

查看远程仓库

bash 复制代码
git remote -v

添加远程仓库

bash 复制代码
git remote add <远程仓库名> <仓库地址>

删除远程仓库

bash 复制代码
git remote remove <远程仓库名>

重命名远程仓库

bash 复制代码
git remote rename <原远程仓库名> <新远程仓库名>

打标签

bash 复制代码
git tag <标签名>

推送标签到远程仓库

bash 复制代码
git push origin <标签名>

删除标签

bash 复制代码
git tag -d <标签名>

删除远程标签

bash 复制代码
git push --delete origin <标签名>
相关推荐
belldeep7 小时前
如何阅读、学习 Git 核心源代码 ?
git·学习·源代码
我不是秃头sheep8 小时前
Git安装教程及常用命令
git
sduwcgg16 小时前
git经验
git
麻雀无能为力16 小时前
git的使用
git
算法歌者19 小时前
Visual Studio 项目 .gitignore 文件指南
git·visual studio
江边垂钓者19 小时前
git cherry-pick和git stash命令详解
git
Lw老王要学习19 小时前
Linux架构篇、第五章git2.49.0部署与使用
linux·运维·git·云计算·it
爱学习的张哥19 小时前
专栏项目框架介绍
git·fpga开发·udp·ddr·gt收发器
Aric_Jones1 天前
lua入门语法,包含安装,注释,变量,循环等
java·开发语言·git·elasticsearch·junit·lua
Sapphire~1 天前
odoo-049 Pycharm 中 git stash 后有pyc 文件,如何删除pyc文件
ide·git·pycharm