{"id":13484012,"url":"https://github.com/b1f6c1c4/learn-git-the-super-hard-way","last_synced_at":"2025-04-06T01:09:17.488Z","repository":{"id":55483842,"uuid":"134733240","full_name":"b1f6c1c4/learn-git-the-super-hard-way","owner":"b1f6c1c4","description":"不走寻常路的Git教程","archived":false,"fork":false,"pushed_at":"2020-12-27T22:11:10.000Z","size":369,"stargazers_count":491,"open_issues_count":2,"forks_count":24,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-30T00:08:31.912Z","etag":null,"topics":["git","git-tutorial","git-workflow","git-workspace","learning-git"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b1f6c1c4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-24T15:15:57.000Z","updated_at":"2025-03-13T03:57:55.000Z","dependencies_parsed_at":"2022-08-15T01:20:45.071Z","dependency_job_id":null,"html_url":"https://github.com/b1f6c1c4/learn-git-the-super-hard-way","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Flearn-git-the-super-hard-way","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Flearn-git-the-super-hard-way/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Flearn-git-the-super-hard-way/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Flearn-git-the-super-hard-way/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b1f6c1c4","download_url":"https://codeload.github.com/b1f6c1c4/learn-git-the-super-hard-way/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247419860,"owners_count":20936012,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","git-tutorial","git-workflow","git-workspace","learning-git"],"created_at":"2024-07-31T17:01:17.970Z","updated_at":"2025-04-06T01:09:17.471Z","avatar_url":"https://github.com/b1f6c1c4.png","language":null,"funding_links":[],"categories":["Others"],"sub_categories":[],"readme":"# learn-git-the-super-hard-way\n\n[GitBook](https://app.gitbook.com/@b1f6c1c4/s/learn-git-the-super-hard-way/)\n\n## 目录\n\n0. [创建工作环境](chapter0.md)（`git init`）\n1. [直接操纵对象](chapter1.md)（`git commit`）\n2. [直接操纵引用](chapter2.md)（`git branch`）\n3. [直接操纵索引](chapter3.md)（`git add / restore`）\n4. [直接操纵HEAD](chapter4.md)（`git switch`）\n5. [直接操纵远程](chapter5.md)（`git pull / push`）\n6. [直接操纵merge](chapter6.md)（`git diff / merge`）\n7. [直接操纵commit](chapter7.md)（`git rebase`）\n8. [检索与查看历史](chapter8.md)（`git log / blame / grep`）\n9. [邪恶的submodule](chapter9.md)（`git submodule`）\n10. [批处理与自动化](chapter10.md)\n11. [配置和alias](chapter11.md)（`git config`）\n12. [单repo多分支工作流](chapter12.md)\n13. [GPG签名](chapter13.md)\n14. [数据的导入和导出](chapter14.md)（`git archive`）\n15. [数据抢修与急救](chapter15.md)\n\n**本教程还提供了[cheatsheet](cheatsheet.md)**，可以用来复习并检查学习效果。\n\n如果你完全没有听说过cheatsheet里面的任何一条命令，那么你可能需要先学习一些基础教程：[入门](https://try.github.io)、[初级](https://learngitbranching.js.org)、[高级](https://git-scm.com/book/en/v2)。其中高级可以跟本教程同时学习。\n\n如果你已经完全掌握cheatsheet里面的所有命令，那么此教程可能对你来说太过浅显，建议移步[Git Reference](https://git-scm.com/docs)、[Git源码](https://github.com/git/git)。\n\n学习完本教程以后，你应该掌握了git的全部用法的1%。\n\n备注：`git reset`/`git checkout`的详解在第4章。强烈推荐改用功能更强大更直观的`git restore`和`git switch`。\n\n## 基本约定\n\n为了更为本质地了解Git，本文会对同一种操作介绍多种不同的实现方法。\n下表描述了不同使用场景下应该如何选择最适合的实现方法。\n\n| 等级 | 含义 | 使用场景 |\n| --- | --- | --- |\n| Lv0 | 纯粹手工实现，完全不使用Git命令行 | 学习Git内部结构时 |\n| Lv1 | 使用底层Git命令行配合手工实现 | 实现极为特殊的Git操作时 |\n| Lv2 | 使用底层Git命令行实现 | 实现非常规Git操作时 |\n| Lv3 | 使用常规Git命令行实现 | 日常使用 |\n| Lv4 | Git Alias | 对Git进行扩展，日常使用 |\n| Lv5 | 编写脚本调用Git命令行 | 对Git进行非常规扩展，偶尔使用 |\n\n## Git命令行基础\n\n### 全局命令行参数\n\n- cwd默认为.，表示先cd到那里再运行后续命令\n- work-tree默认为`GIT_WORK_TREE`或者`.`，但并非所有命令都涉及worktree\n- git-dir默认为`GIT_DIR`或者`./.git`：\n  - 若./.git是目录，则就以该目录为repo\n  - 若./.git是文件，则以该文件内容（一般会是绝对路径）为repo\n\n```bash\ngit [-C \u003ccwd\u003e] [--git-dir=\u003crepo\u003e] [--work-tree=\u003cworktree\u003e] \u003ccommand\u003e [args]\n```\n\n### 具体Git命令的参数\n\n大部分命令的参数列表遵循以下格式：\n- object是对象的表达式\n  - 一般由引用、对象SHA1、^、~、:等构成\n  - 完整列表参见`git rev-parse`（Lv2）\n- path是路径\n- `--`在不引起歧义的情况下可以省略\n\n注意：是否存在`\u003cpath\u003e`参数可能对语义有本质的影响\n\n```bash\ngit \u003ccommand\u003e [options] [\u003cobject\u003e]\ngit \u003ccommand\u003e [options] [\u003cobject\u003e] -- [\u003cpath\u003e]\n```\n\n## Git命令列表\n\n本教程涵盖所有的Git常用命令和一半以上的Git非常用命令，\n参见[Roadmap](ROADMAP.md)\n\n## License\n\n\u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\"\u003e\u003cimg alt=\"Creative Commons License\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png\" /\u003e\u003c/a\u003e\u003cbr /\u003eThis work is licensed under a \u003ca rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc-sa/4.0/\"\u003eCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International License\u003c/a\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1f6c1c4%2Flearn-git-the-super-hard-way","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb1f6c1c4%2Flearn-git-the-super-hard-way","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1f6c1c4%2Flearn-git-the-super-hard-way/lists"}