Git 学习
-
分布式控制工具,版本控制工具,多人开发,协同开发
-
对应的其实还有集中式控制工具,比如
SVN
VSS
等等 -
淘宝镜像 下载git淘宝镜像
http://npm.taobao.org/mirrors/git-for-windows/
git bash基本命令
cd
cd ..
pwd
clear
ls
touch
rm
mkdir
rm -r
help
man
exit
git 环境配置
- 查看全局配置
git config --system --list
- 查看用户配置,对应文件,C盘
.gitconfig
git config --global --list
- 配置用户名和密码
git config --global user.name xpc
git config --global user.email 2326658837@qq.com
git 基本理论
- git 有四个工作区,本地工作目录,暂存区,资源库,远程仓库
上传文件
working directory [git add] stage [git commit] repository [git push] remote directory
下载文件
remote directory [git pull] working directory
remote [git clone] repository [checkout] working directory
git 项目创建及克隆
- 在当前文件夹创建Git代码库
在文件路径下面打开git bash
git init
- 克隆别人的一个项目和它的整个历史
git clone [url]
git 的基本操作命令
git status //查看所有文件的状态,如果未被add(未被跟踪untracked files)就会被提示
git add . //添加所有文件到暂存区
git commit -m "提示信息" //提交到本地仓库
//上传的时候可以过滤一些不必要的文件,需要创建一个.gitignore文件,语法如下
*.txt
*.idea
target/
target/*.txt
配置SSH公匙
- 默认生成路径是在administrator/.ssh目录下
ssh-keygen -t rsa //以rsa的加密方式生成公匙
在idea中使用git【单分支开发】
-
把一个idea项目和git远程仓库连接起来,只需要把从远程仓库clone下来的文件复制到idea项目中即可
-
在idea中配置git
- file->settings->version control->git
- 选择自己安装好的git 的bin目录下面的
git.exe
-
在terminal控制台操作
- git add . 所有红色文件会提交到暂存区 变成绿色
- git commit -m “提示信息” 所有文件会提交到本地仓库
- git push 直接提交到远程仓库了
-
实现commit过程中的文件过滤,在
.gitignore
文件中配置好后就可以过滤
*.txt
*.idea
target/
target/*.txt
多分支开发
Git鼓励大量使用分支:
查看分支:git branch
创建分支:git branch <name>
切换分支:git checkout <name>或者git switch <name>
创建+切换分支:git checkout -b <name>或者git switch -c <name>
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>