一、Git安装
1、windows和mac系统下的安装
。。。
2、Linux操作系统的安装
Ubuntu : sudo apt-get install git
CentOS: sudo yum install git
3、检验是否安装成功
打开gitbash命令行工具,输入命令 git --version
查看git版本

二、git结构和状态
1、git的三层结构
working directory 工作区
staging index 暂存区
git directory(Repository) 版本库
2、git文件中的4种状态
untracked 未被追踪
Modified 表示工作区修改了某个文件但是还没有添加到暂存区
Staged 表示把工作区修改的文件添加到了暂存区但是没有提交到版本库
Commited 表示数据安全的存储在本地库中

三 、git基本命令
1、初始化git仓库 git init
2、
将文件添加到暂存区
git add filename
将工作目录下的所有文件都添加到暂存区
git add .
3、
将暂存区内的文件提交到版本库
git commit -m '本次提交版本名称'
跳过git add 添加到暂存区命令,直接将工作区所有已跟踪的文件提交
git commit -am '本次提交的版本名称'
4、查看git提交日志 git log
5、查看项目文件状态 git status
6、git config
git config --global user.name #创建本地用户
git config --global ***@email.com
git config --list
地址~/.gitconfig

四 、git撤销操作
1、撤销上一次提交,并将暂存区的文件重新提交 git commit --amend
2、拉取暂存区文件并将其替换工作区的文件 git checkout -- filename
3、拉取最近一次提交的版本库中的这个文件到暂存区,该操作不影响工作区
git reset HEAD filename
4、git reset --option 版本号

五、git文件删除
1.删除工作区及暂存区中的该文件,相当于删除后执行git add
git rm filename
2.在不小心将不需要追踪的文件添加到暂存区,想删除暂存区的文件但不想删除工作区的文件
git rm --cached filename
3.当工作区或者暂存区文件修改了
git rm -f filename

六、git分支
1、git分支的创建、修改、切换、删除
git branch
查看分支
git branch [分支名称]
创建新的分支
git checkout [分支名称]
切换到指定分支
git checkout -b [分支名称]
创建并切换到新的分支
git branch -m oldname newname
对分支重命名
git branch -D [分支名称]
删除分支

2、分支合并
git merge [分支名称]
git分支合并,主要命令


3、储存变更
作用:当一个分支的工作区进行了修改操作,并且没有提交,这时直接切换到另一个分支,这个分支工作区修改的内容会覆盖另一个分支的工作区内容,为了防止这样的事情发生,在切换分支前,可以先将工作区修改为添加的内容,存储到一个临时存储区,然后切换到另一个分支就不会影响另一个分支工作区内容,当回到该分支的时候,可以将临时存储区里的存储内容拉取出来继续使用。





七、git远程仓库

- git remote 对远程仓库地址命名
作用:远程仓库地址一般是一长串url,为了便捷,不用每次和远程仓库交互都输入一长串地址,对这串地址进行命名,之后输入和远程仓库交互输入这个命名就可以了。
1、git remote add [远程仓库名] 远程仓库地址
对地址进行命名
2、git remote -v
查看地址命名

3、git push [远程仓库名] [分支名称]
git用remote名称提交到远程仓库

- 通过ssh免密登陆获取github/远程仓库上的代码
1、在桌面右键点击git Bash Here进入git命令行窗口
2、输入ssh-keygen
命令,回车
3、在 C:\Users\wangshuqi\.ssh目录下会出现id_rsa.pub文件

4、 记事本打开这个文件,Ctrl+A选中全部内容,然后复制其中内容

5、登录github网站后,添加ssh key


6、复制github远程下载路径

7、打开git命令行,执行
git pull **
命令下载github远程仓库的代码
网友评论