如何慢慢学习 Git。
也可在我的博客上找到。
这篇文章献给我的妻子,尽管她是我认识的最聪明的人之一,但她仍然不擅长使用 Git
我指导 Web 开发学生已经有一段时间了。因此,我非常了解初学者常犯的错误。
我之前写过一篇关于如何开始学习 CSS 的文章- 对于任何 CSS 初学者来说都是一篇值得一读的文章。
现在是时候掌握 Git 了。Git……并不容易掌握。
这就是为什么初学者很容易感到困惑。一次失误可能会付出高昂的代价:没人想成为那个删除同伴成果的人。
学习 Git 的最佳方法是循序渐进。成为真正的 Git 大师可能需要相当长的时间。
本指南旨在通过清晰易懂的步骤,组织您的学习路径,让您的学习之旅更加轻松。在进入下一级别之前,请务必充分掌握每个级别!
I - 基本单独使用
这些工具将允许您将 Git 用于您自己的用途。目前无需考虑分支,只需在主分支上执行所有操作即可。
要完全理解的概念:
- What is the difference between Git and Github?
- What is a commit?
- What is the staging phase?
- What is a branch?
- What's the remote repository VS local repository?
- How to set one or more upstream repository?
- How to commit?
- How to push / pull to an upstream repository?
需要完全了解的命令:
git init
git clone <repository>
git status
git add <file>
git add --all
git commit
git remote add
git remote set-url
git remote -v
git push <repository> <branch>
git pull <repository> <branch>
II-基本工具
这些工具将帮助你更轻松地使用 Git 作为工作工具。我们还需要学习一些配置知识。
要完全理解的概念:
- The .gitignore file
- The .gitconfig file
- Seeing the commit log
- File manipulation with Reset, Clean, Checkout <file>, Rm
- Repo manipulation with the Stash
需要完全了解的命令:
git log (with and without --stat)
git checkout <file>
git reset <file> (DANGEROUS!)
git reset --hard (DANGEROUS!)
git clean -f (DANGEROUS!)
git rm <file> (DANGEROUS!)
git config --global user.name
git config --global user.email
git stash
git stash apply
git stash clear (Kinda dangerous)
III-基础协作
这将帮助你开始与他人合作。在尝试任何合作之前,你需要先掌握这一级别。
要完全理解的概念:
- Branchs: What they are, why they exist, how to use them.
- Merging
- Conventions for branch naming
- How to write good commit messages
- What are forked repositories?
需要完全了解的命令:
git merge
git branch
git checkout <branch>
git checkout -b
git blame <file>
IV - 基础协作:Rebase 和 Pull 请求
我把整个“重新定位到协作分支”放在一边,因为它添加了第一个可能损坏远程存储库的命令:git push --force-with-lease
。
确实,如果你正在 rebase 本地分支,你需要使用此选项推送到远程仓库。所以这很危险,但如果你在团队中协作,你仍然需要掌握这部分。
我还在这里添加了拉取请求,因为它们是一个重要的概念,但它们更多的是一个 Github/Gitlab 概念,而不是一个 Git 概念。
要完全理解的概念:
- Simple rebase (and how it differs from merging)
- What are pull requests?
- How to make a PR from branch to branch
- How to make a PR from a fork to the original repository
需要完全了解的命令:
git rebase
git push --force-with-lease (DANGEROUS)
V - 胜任水平
此级别允许您更好地组织您的工作历史、组织您的分支并轻松浏览您的历史。
要完全理解的概念:
- How to rewrite your local history
- How to rebase interactively
- Branch management (prune, fetch)
- Use of HEAD notation or commit hashes
- Using Diff to compare commits
- How to revert a commit
需要完全了解的命令:
git commit --amend
git rebase -i
git prune
git fetch
git remote prune
git checkout HEAD/HEAD~1/<commit hash>
git diff <commit hash 1> <commit hash 2>
git revert <commit hash>
VI-高级
在这个级别,当您或其他人搞砸某件事时,您可以修复它。
要完全理解的概念:
- What is the reflog?
- How to clean sensitive data from the repository
- How to effectively hunt for bad commits
需要完全了解的命令:
git reflog
git-filter-branch
git-filter-repo
git bisect
作为 git-filter 命令的绝佳替代方案,我建议使用BFG。
结论
我希望本指南能帮助您顺利通过第一次学习 Git 的危险路线。
如果我忘记了您经常使用的重要命令,请务必告诉我!
编码愉快!
文章来源:https://dev.to/samuelfaure/how-to-learn-git-slowly-38fa