1 本地仓库
创建一个文件夹,输入git init
,这个文件夹将初始化为仓库。
仓库分为三个维度
- 工作区域
- 暂存区域
- 仓库区域
git add file
:将会跟踪这个file
,将file
放入暂存区域。
git commit -m "xxx"
: 引号的内容尽量用祈使句,暂存区提交到仓库。
以上就是一个提交过程。
win10系统的编码警告:
$ git add version_1.txt
warning: LF will be replaced by CRLF in version_1.txt.
The file will have its original line endings in your working directory
$ git config core.autocrlf
true
$ git config --global core.autocrlf false
git log
:可以查看提交日志,通过git checkout xxx
可以回到以前的版本。
git diff
:对比工作区与暂存区的差别。
git diff --staged
:对比暂存区与仓库的差别。
git reset --hard
:清空工作区与暂存区,回到上次提交。
2 分支
git brach
:查看分支情况,符号 * 表示所在分支
$ git branch
* master
test
git checkout test
:选择到test
分支。
当在分支test
,作出更新并提交后,可切换到master
分支进行合并。
git checkout master
git merge master test
当master
分支和test
分支都有被修改时,合并时会出现冲突,冲突的提示会增加到源文件,打开源文件,自行查看修改。
3 远程仓库
本地仓库执行命令
git remote add origin https://github.com/xxx/xxx.git
git remote
:查看
$ git remote
origin
$ git remote -v
origin https://github.com/juzhango/git_intro.git (fetch)
origin https://github.com/juzhango/git_intro.git (push)
git push origin master
:将本地文件上传到远程仓库。
git pull origin master
:将云端文件拉取到本地。
相关连接
https://www.bilibili.com/video/av414032616?p=1
https://git-scm.com/book/zh/v2