{"id":16347077,"url":"https://github.com/ospoon/gitcourse","last_synced_at":"2025-11-09T02:30:27.995Z","repository":{"id":105556727,"uuid":"160478269","full_name":"OSpoon/GitCourse","owner":"OSpoon","description":"GitCourse 整理git常见用法及使用流程","archived":false,"fork":false,"pushed_at":"2018-12-07T02:01:57.000Z","size":67917,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T06:09:41.725Z","etag":null,"topics":["git"],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OSpoon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-05T07:28:09.000Z","updated_at":"2018-12-13T09:26:06.000Z","dependencies_parsed_at":"2024-03-30T18:48:17.802Z","dependency_job_id":null,"html_url":"https://github.com/OSpoon/GitCourse","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/OSpoon%2FGitCourse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSpoon%2FGitCourse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSpoon%2FGitCourse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OSpoon%2FGitCourse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OSpoon","download_url":"https://codeload.github.com/OSpoon/GitCourse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239565664,"owners_count":19660158,"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"],"created_at":"2024-10-11T00:39:35.244Z","updated_at":"2025-11-09T02:30:27.964Z","avatar_url":"https://github.com/OSpoon.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"### GIT使用\n\n[TOC]\n\n#### 基本命令\n\n| 命令                       | 解释                         |\n| :------------------------- | :--------------------------- |\n| mkdir gitdemo              | 创建gitdemo目录              |\n| cd gitdemo                 | 进入gitdemo目录              |\n| git init                   | 初始化                       |\n| ls -a                      | 查看当前目录文件包含隐藏文件 |\n| echo “内容” \u003e\u003e xxx.txt     | 输入内容到xxx文件            |\n| git add test.txt           | 添加test.txt到暂存区         |\n| git commit -m \"提交信息\"   | 提交修改信息                 |\n| git status                 | 查看当前版本库               |\n| git reset HEAD newday.txt  | 将此文件恢复工作区           |\n| git checkout -- newday.txt | 回滚到修改前                 |\n| git log                    | 查看提交日志                 |\n| git reset --hard b7a3a3b60 | 回滚指定版本库               |\n| git rm test2.txt           | 删除指定文件                 |\n\n| 命令                            | 解释                                                         |\n| ------------------------------- | ------------------------------------------------------------ |\n| git init                        | 初始化本地git环境                                            |\n| git clone XXX                   | 克隆一份代码到本地仓库                                       |\n| git pull                        | 把远程库的代码更新到工作台                                   |\n| git pull --rebase origin master | * 强制把远程库的代码跟新到当前分支上面                       |\n| git fetch                       | 把远程库的代码更新到本地库                                   |\n| git add                         | 把本地的修改加到stage中                                      |\n| git commit -m 'comments here'   | 把stage中的修改提交到本地库                                  |\n| git push                        | 把本地库的修改提交到远程库中                                 |\n| git branch -r/-a                | 查看远程分支/全部分支                                        |\n| git checkout master/branch      | 切换到某个分支                                               |\n| git checkout -b test            | 新建test分支                                                 |\n| git checkout -d test            | 删除test分支                                                 |\n| git merge master                | 假设当前在test分支上面，把master分支上的修改同步到test分支上 |\n| git merge tool                  | 调用merge工具                                                |\n| git stash                       | 把未完成的修改缓存到栈容器中                                 |\n| git stash list                  | 查看所有的缓存                                               |\n| git stash pop                   | 恢复本地分支到缓存状态                                       |\n| git blame someFile              | 查看某个文件的每一行的修改记录（）谁在什么时候修改的）       |\n| git status                      | 查看当前分支有哪些修改                                       |\n| git log                         | 查看当前分支上面的日志信息                                   |\n| git diff                        | 查看当前没有add的内容                                        |\n| git diff --cache                | 查看已经add但是没有commit的内容                              |\n| git diff HEAD                   | 上面两个内容的合并                                           |\n| git reset --hard HEAD           | 撤销本地修改                                                 |\n| echo $HOME                      | 查看git config的HOME路径                                     |\n| export $HOME=/c/gitconfig       | 配置git config的HOME路径                                     |\n\n来源: [https://www.cnblogs.com/allanli/p/git_commands.html](https://www.cnblogs.com/allanli/p/git_commands.html \"来源\")\n\n#### 本地仓库\n\n##### 一 准备工作\n\n1.创建本地版本库\n\n```\ngit init\n```\n\n2.添加work.txt到暂存区\n\n```\ngit add work.txt\n```\n\n3.提交暂存区内容到版本库\n\n```\ngit commit -m \"提交提一天工作内容\"\n```\n\n##### 二 临时变更需求\n\n1.完成变更\n\n2.添加work.txt到暂存区\n\n```\ngit add work.txt\n```\n\n3.变更撤销（暂存区回滚）\n\n```\ngit reset HEAD work.txt 还原暂存区\ngit checkout -- work.txt 还原工作区\n```\n\n##### 三 新需求接入\n\n1.完成新需求\n\n2.添加work.txt到暂存区\n\n```\ngit add work.txt\n```\n\n3.提交暂存区内容到版本库\n\n```\ngit commit -m \"提交新需求内容\"\n```\n\n4.需求撤销（版本库回滚）\n\n```\ngit reset --hard 96f9ac717f6c9ed1eefab72746089bce39d65323\n```\n\n5.全功能撤销\n\n```\ngit rm work.txt 删除工作区内容\ngit commit -m “功能撤销删除文件” 删除暂存区，版本库\n```\n\n#### 远程仓库\n\n##### 一 配置SSH\n\n```\ncd ~/.ssh / cd .ssh/ 查看是否存在rsa\nssh-keygen -t rsa -C \"zxin088@gmail.com\" 创建公钥\ncat id_rsa.pub 获取密钥\nssh -T git@github.com 检测连通\n```\n\n##### 二 添加远程仓库\n\n1. or create a new repository on the command line\n\n```\necho \"# sublife_git\" \u003e\u003e README.md\t创建README.md文件\ngit init\t初始化仓库\ngit add README.md\t添加README.md到暂存区\ngit commit -m \"first commit\" 提交README.md到仓库\ngit remote add origin https://github.com/OSpoon/sublife_git.git 关联远程仓库\ngit push -u origin master 推送README.md到远程仓库\n```\n\n2. or push an existing repository from the command line\n\n```\ngit remote add origin https://github.com/OSpoon/sublife_git.git 关联远程仓库\ngit push -u origin master 推送本地仓库内容至远程仓库\n```\n\n##### 三 克隆仓库\n\n```\n//拉取仓库\ngit clone git@github.com:OSpoon/sublife_git.git 拉取远程仓库\n//变更内容\necho “clone demo” \u003e\u003e clone.txt\ncat clone.txt\n//添加暂存-\u003e提交版本库-\u003e推送远程仓库\ngit add clone.txt\ngit commit -m \"first clone\"\ngit push\n```\n\n##### 四 标签管理\n\n| 命令                                 | 解释         |\n| ------------------------------------ | ------------ |\n| git tag                              | 查看所有标签 |\n| git tag name                         | 创建标签     |\n| git tag -a name -m \"comment\"         | 指定提交信息 |\n| git tag -d name                      | 删除标签     |\n| git push origin name                 | 标签发布     |\n| git push origin :refs/tags/\u003ctagname\u003e | 删除远程标签 |\n\n##### 五 分支管理\n\n| 命令                   | 解释         |\n| ---------------------- | ------------ |\n| git branch feature_1   | 创建分支     |\n| git branch             | 查看分支     |\n| git checkout feature_1 | 切换指定分支 |\n\n1. 合并分支到master主分支\n\n   ```\n   git checkout master 切回master分支\n   git merge feature_1 合并feature_1到master\n   git branch -d feature_1 删除废弃分支\n   ```\n\n\n#### 团队协作git操作流程\n\n  来源: [https://www.cnblogs.com/allanli/p/git_commands.html](https://www.cnblogs.com/allanli/p/git_commands.html \"来源\")\n\n##### 一 克隆一个全新的项目，完成新功能并且提交\n\n1. git clone XXX //克隆代码库\n2. git checkout -b test //新建分支\n3. modify some files //完成修改\n4. git add . //把修改加入stage中\n5. git commit -m '' //提交修改到test分支\n6. review代码\n7. git checkout master //切换到master分支\n8. git pull //更新代码\n9. git checkout test //切换到test分支\n10. git meger master //把master分支的代码merge到test分支\n11. git push origin 分支名//把test分支的代码push到远程库\n\n##### 二 目前正在test分支上面开发某个功能，但是没有完成。突然一个紧急的bug需要处理\n\n1. git add . //把修改加入stage中\n2. git stash //暂存当前修改内容\n3. git checkout bugFixBranch //切换fix分支\n4. git pull --rebase origin master \n5. fix the bug //修改bug\n6. git add . //添加暂存区\n7. git commit -m '' //提交版本库\n8. git push //推送远程仓库\n9. git checkout test //捡出test分支\n10. git stash pop //弹出修改内容\n11. continue new feature's development //继续开发test分支","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fospoon%2Fgitcourse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fospoon%2Fgitcourse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fospoon%2Fgitcourse/lists"}