一、名词:
- 工作区(workspace) :平时些的代码都在工作区
- 暂存区(index/Stage) :工作区代码执行add命令后将代码提交到暂存区
- 本地仓库(Repository) :暂存区代码执行commit命令将代码提交到本地版本库
- 远程仓库(Remote) :本地仓库代码执行push命令将代码提交到远程仓库
二、本地git服务器搭建
https://blog.youkuaiyun.com/qiuyufeng/article/details/81040127
三、常用命令
命令
| 功能 | 常用指令 |
---|---|---|
git add | 将文件从工作区添加到暂存区 | 【git add file1 file2】将文件file1,file2从工作区添加到暂存区 【git add .】将当前目录的所有文件添加到暂存区 【git mv file1 file2】将file1改名成file2并放到暂存区 |
git commit | 将文件从暂存区添加到本地仓库 | 【git commit -m [message]】将暂存区中的文件提交到本地仓库,并附带log 【git commit [file1][file2] -m [message]】将指定文件添加到本地仓库(这个指令前也需要add,只是将暂存区中的指定文件添加到本地仓库,并不能取代add指令) 【git commit -a】将已受版本控制的文件上传到本地仓库,类似于指令git add指令之后执行git commit。但是当有新增加的文件时是不能直接使用,需要提前add 【git commit -v】将暂存区的文件上传到本地仓库。与【git commit -a】的区别在于使用-v前不只是新添加的文件需要add,被修改的文件也需要add 【git commit --amend -m [message]】修改上次commit的log信息(只修改最近一次的) |
git push | 将本地仓库文件推送到远端仓库 | 无 |
git branch | 分支指令 | 【git branch】列出本地分支 【git branch -r】列出远端分支 【git branch -a】列出所有分支(本地+远端) 【git branch [branch-name]】新建一个分支,但不切换(仍在当前分支) 【git checkout -b [branch-name]】新建一个分支并切换到该新分支上 【git checkout [branch-name]】切换到指定分支上,并更新工作区 【git push --set-upstream origin [branch-name]】在远端建立一个分支与本地branch分支相对应起来 【git merge [branch-name]】合并指定分支到当前分支 【git branch -d [branch-name]】删除本地分支 【git push origin --delete [branch-name]】删除远端分支 |
git tag | 标签指令 | 【git tag】列出本地现有标签 【git tag -n】列出所有标签并附带标签信息 【git tag [tag_name]】打标签 【git tag [tag_name] -m [info]】创建一个标签并附带说明 【git tag -a [tag_name] [commit]】对指定commit创建标签 【git tag -a [tag_name] -m [info] [commit]】对指定commit创建标签并附带信息 【git push origin v0.1.2】将v0.1.2标签提交到git服务器 【git push origin –tags】将本地所有标签一次性提交到git服务器 【git tag -d [tagname]】删除本地标签 【git push origin --delete [tagname]】删除远端标签 |
git remote | 远端指令 | 【git remote -v】显示所有远程仓库 【git remote add [name] [url] 】添加远端版本库 如:git remote add origin git@github.com:tianqixin/runoob-git-test.git 【git remote rm [name]】 删除远程仓库 |