💡
原文英文,约500词,阅读约需2分钟。
📝
内容提要
版本控制对开发者至关重要,Git是标准工具。本文提供了Git速查表,涵盖初始化仓库、克隆、跟踪更改、分支管理、推送和拉取更新等基本命令,帮助用户快速上手,提高生产力。
🎯
关键要点
- 版本控制对开发者至关重要,Git是标准工具。
- Git帮助管理代码更改、跟踪历史、进行安全实验和跨分支工作。
- 本文提供了Git速查表,涵盖初始化仓库、克隆、跟踪更改、分支管理、推送和拉取更新等基本命令。
- 初始化仓库使用命令:git init。
- 克隆现有仓库使用命令:git clone <repo-url>。
- 跟踪和保存更改的命令包括:git add <file>、git commit -m 'your message'、git status、git diff。
- 创建分支使用命令:git branch <branch-name>,切换分支使用命令:git checkout <branch-name>。
- 合并分支使用命令:git merge <branch-name>。
- 推送更改使用命令:git push origin <branch>,拉取更新使用命令:git pull origin <branch>。
- 查看历史使用命令:git log。
- 撤销提交使用命令:git revert <commit-hash>。
- 重置提交使用命令:git reset --soft HEAD~1、git reset --mixed HEAD~1、git reset --hard HEAD~1。
- 暂存工作使用命令:git stash、git stash apply。
- 选择性应用提交使用命令:git cherry-pick <commit-hash>。
- 重基分支使用命令:git rebase <branch>。
- 使用Git Hooks自动化任务。
- 创建别名使用命令:git config --global alias.co checkout。
- 流行的Git工作流程包括集中式工作流程、特性分支工作流程和Gitflow。
❓
延伸问答
如何初始化一个Git仓库?
使用命令:git init。
如何克隆一个现有的Git仓库?
使用命令:git clone <repo-url>。
如何查看Git的提交历史?
使用命令:git log。
如何创建和切换分支?
创建分支使用命令:git branch <branch-name>,切换分支使用命令:git checkout <branch-name>。
如何推送和拉取更新?
推送更改使用命令:git push origin <branch>,拉取更新使用命令:git pull origin <branch>。
如何撤销一次提交?
使用命令:git revert <commit-hash>。
➡️