Github实用CheatSheet

Git Cheat Sheet

初始化仓库或克隆现有仓库

配置Git

  • 配置用户信息(首次使用Git时)
    git config –global user.name “Your Name”
    git config –global user.email “youremail@example.com

基本Git操作

  • 查看状态
    git status

  • 跟踪新文件或暂存已修改的文件
    git add filename
    git add .

  • 提交更改
    git commit -m “Commit message”

  • 查看提交历史
    git log

分支管理

  • 列出所有分支
    git branch -a

  • 创建新分支
    git branch new-branch-name

  • 切换分支
    git checkout branch-name

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

  • 合并分支
    git merge source-branch

  • 删除分支
    git branch -d branch-name

远程操作

  • 查看远程仓库
    git remote -v

  • 推送更改到远程仓库
    git push origin branch-name

  • 从远程仓库拉取最新内容
    git pull origin branch-name

撤销更改

  • 撤销工作目录中所有未暂存的更改
    git checkout .

  • 将文件回退到上一个提交的状态
    git checkout HEAD^ filename

  • 重置暂存区到最近一次git commit的状态
    git reset
    git reset –hard HEAD

高级操作

  • 交互式暂存
    git add -i

  • 查看特定文件的修改历史
    git log -p filename

  • 暂存当前工作进度
    git stash
    git stash pop

  • 使用变基代替合并(谨慎使用)
    git rebase master


Github实用CheatSheet
http://pafl.top/2024/03/26/Github实用CheatSheet/
Author
Paf
Posted on
March 26, 2024
Licensed under