git基本用法

原理图:

显示工作目录和暂存区的状态。

git status

三种状态:已提交(committed)已修改(modified)已暂存(staged)

配置

复制代码
git config --global user.name "Your Name"

管理分支

  • 查看分支:git branch

  • 创建新分支: git branch <branch-name>

  • 切换分支: git checkout <branch-name>

  • 创建并切换到新分支: git checkout -b <branch-name>

  • 合并分支: git merge <branch-name>

提交代码

把代码提交到暂存区:git add .

提交暂存区的更改到本地仓库:git commit -m "Commit message"

推送更改到远程仓库:git push origin <branch-name>

回退和恢复

  • 回退到指定提交: git reset --hard <commit-hash>

  • 恢复已删除的文件: git checkout -- <file>

重置本地分支到远程分支:git reset --hard origin/main

清除未跟踪的文件:git clean -fd

相关推荐
nyf_unknown8 小时前
(vue)将文件夹打成tar包, Git Bash(推荐)具体使用
vue.js·git·bash
兔老大RabbitMQ8 小时前
Git Revert 特定文件/路径的方法
git
星哥说事1 天前
如何将堡塔云WAF迁移到新的服务器
服务器·git·github
阿政一号1 天前
Git版本控制器
git
妮妮喔妮1 天前
SSH协议的GIT转换
运维·git·ssh
今禾1 天前
Git 日常使用与面试考点详解:从入门到精通
前端·git·面试
Data_Adventure2 天前
能连上 GitHub(SSH 验证成功),却 push 失败?常见原因与逐步解决方案
前端·git·github
间彧2 天前
如何解决Git客户端下载缓慢问题
git
Tearstornbyrain2 天前
在Ubuntu24.04中使用ssh连接本地git仓库到github远程仓库
linux·git·ubuntu·ssh·github
四七伵2 天前
一次 Git Rebase 事故,让我彻底明白 Rebase 和 Merge 的区别
git·后端