Git 和 Github 备忘单 2022 Git 备忘单 ❤️ 在 GITHUB 上赞助我 ❤️

2025-06-04

Git 和 Github 速查表 2022

Git 备忘单

❤️ 在 GITHUB 上赞助我 ❤️

当然!这是你的 Git 速查表的 Markdown 修订版和格式化版本:


Git 备忘单

Git 是一个免费的开源分布式版本控制系统,负责管理您计算机上所有与 GitHub 相关的操作。本备忘单列出了最重要和最常用的 Git 命令,方便您参考。

安装和 GUI

GitHub 为 Git 提供了特定于平台的安装程序,提供命令行工具和图形用户界面 (GUI),用于日常交互、审查和存储库同步。

设置

配置所有本地存储库使用的用户信息:

git config --global user.name "[firstname lastname]"
git config --global user.email "[valid-email]"
git config --global color.ui auto
Enter fullscreen mode Exit fullscreen mode

设置和初始化

配置用户信息、初始化和克隆存储库:

git init
git clone [url]
Enter fullscreen mode Exit fullscreen mode

阶段和快照🔽

使用快照和 Git 暂存区:

git status
git add [file]
git reset [file]
git diff
git diff --staged
git commit -m "[descriptive message]"
Enter fullscreen mode Exit fullscreen mode

分支与合并

隔离分支中的工作、更改上下文并整合变更:

git branch
git branch [branch-name]
git checkout [branch]
git merge [branch]
git log
Enter fullscreen mode Exit fullscreen mode

检查并比较🔽

检查日志、差异和对象信息:

git log
git log branchB..branchA
git log --follow [file]
git diff branchB...branchA
git show [SHA]
Enter fullscreen mode Exit fullscreen mode

跟踪路径变化

版本控制文件删除且路径更改:

git rm [file]
git mv [existing-path] [new-path]
git log --stat -M
Enter fullscreen mode Exit fullscreen mode

忽略模式

防止意外暂存或提交文件:

创建.gitignore具有模式的文件:

logs/
*.notes
pattern*/
Enter fullscreen mode Exit fullscreen mode

为所有本地存储库设置系统范围的忽略模式:

git config --global core.excludesfile [file]
Enter fullscreen mode Exit fullscreen mode

分享和更新🔽

从另一个存储库检索更新并更新本地存储库:

git remote add [alias] [url]
git fetch [alias]
git merge [alias]/[branch]
git push [alias] [branch]
git pull
Enter fullscreen mode Exit fullscreen mode

重写历史

重写分支、更新提交并清除历史记录:

git rebase [branch]
git reset --hard [commit]
Enter fullscreen mode Exit fullscreen mode

临时提交

临时存储已修改、已跟踪的文件以更改分支:

git stash
git stash list
git stash pop
git stash drop
Enter fullscreen mode Exit fullscreen mode

这份速查表涵盖了各种任务所需的 Git 命令。请将其放在手边,以便快速参考!

❤️ 在 GITHUB 上赞助我 ❤️

图片描述

我的其他博客

文章来源:https://dev.to/ankushsinghgandhi/git-github-cheat-sheet-71b
PREV
我在 Devto 上的浏览​​量从 0 增长到 100 万:10 个技巧和经验!🎉
NEXT
算法与数据结构:资源包算法 - Java