1. Introduction
Git distributed version management tool
Svn centralized version management tool
Second, Git Bash
(1)Shell
The shell is ultimately used to operate the hardware of the computer, whether it is a graphical interface or a command line interface, they all accomplish the same function
- Graphical interface shell
- Command line shell eg:
cmd gitbash
(2) Commonly used commands of git bash
pwd 查看当前的目录
cd 切换目录
ls 列出当面目录中的内容
ls -a 显示隐藏的文件
ls -l 列出文件的详细信息
ls -al(-la)
mkdir 创建目录 可以创建多个文件夹
touch 创建文件 可以创建多个文件
cat 查看文件内容
eg : cat index.html
less 查看文件
eg : less index.html
空格分页阅读
回车换行阅读
q 退出
rm 删除文件 不能删除文件夹
rmdir 删除文件夹 只能删除空的文件夹
rm -r 文件夹 使用递归的方式删除有文件的文件夹
mv 移动文件可以重命名
cp 复制
head 查看文件的前几行
head -n 10 index.html
head -10 index.html
tail 查看文件的后几行
tail -n 10 index.html
tail -10 index.html
history 查看历史
> 和 >> 重定向操作符
echo hello world > abc.txt
ls -al > log.txt
> 覆盖
>> 追加
wegt 下载
tar 解压缩
curl 网络请求 eg : curl www.baidu.com
whoami 查看当前的用户
管道符 | 可以把上一次的命令当成参数传递给下一个命令
grep 匹配内容 一般是跟管道符一起玩
grep div index.html
ls -al | grep css 匹配所有的css文件
(3) Use of Git
1. The workflow of git
工作区->暂存区-> git本地仓库-> git远程仓库(github) 绿色的表示git文件夹中
2. Command to configure user name and mailbox
git config --global user.name "psh"
git config --global user.email "coding****@sian.com"
// 文件创建好后在C:\Users\Administrator中.gitconfig文件中
3. Create a new git project
- Create a new
git
project, just create a new folder, create a new folder, right-gitbash
git init
initializegit
the folder git status
View the status of the file (see whether the file is in the work area or the temporary area).
Red indicates that the file that has not been tracked (in the work area)
is modified. The file has not been placed in the temporary area, and it is all red (in the work Area)
Green means in the temporary storage areagit add *(-A)
Put all the files in the work area into the temporary storage areagit checkout
Restore the files in the temporary storage area to the workspacegit commit -m
"Comments submitted by" all the documents submitted to the staging area ofgit
a local warehousegit log
View the version of history submitted to the git local repository (view.git
all contents in the hidden folder )
7. git reset --hard 唯一ID (可以切换到git本地仓库的任意版本)
(4) Use of Github
使用流程
1. git 本地仓库和远程仓库关联
2. git 项目关联
1. Warehouse association
为了在本地和远程之间进行免密钥登录,可以配置ssh
配置ssh:先在本地配置,发送给远程
ssh-keygen -t rsa -C "coding****@sina.com"
出现如上界面表示ssh生成成功
生成文件 :id_rsa.pub(C:\Users\Administrator\.ssh目录中的)
2. Enter Github-Git local warehouse and Github remote warehouse to associate
1. GitHub 注册成功以后 settings => SSH and GPG keys => New SSH key title 任意写
2. key 中输入刚才本地生成的 ssh * 一定要删掉最后一个换行 *
New SSH Key
Generation: The first git_01 library project
to test whether the communication was successful
SSH -T [email protected]
.ssh folder will be more successful after a known_hosts file
本地仓库和远程仓库已经关联成功 即可以成功通信
3. Association and interaction between Git local projects and Github remote projects
1. 在远程建立项目 Your profile -> Repositories -> new
2. 本地项目和远程项目关联
git remote add origin 项目唯一标识符
此时,本地项目和远程项目已经关联成功
4. Local project and remote project communication
1. 第一次发布项目 (本地->远程) 把.git 隐藏文件中的所有内容全部放到 github 中
git push -u origin master
2. 第一次下载项目 (远程-本地)
git clone 项目唯一标识符
3. 提交(本地-远程)
git push origin master
4. 更新(远程-本地)
git pull
~~~~~~~~~~~~~~~~~~~ END ~~~~~~~~~~~~~~~~~~~