一、Git的文件状态
已修改
在工作目录修改Git文件
已暂存
对修改的文件执行Git暂存操作,将文件纳入暂存区
已提交
将暂存的文件执行Git提交操作,将文件纳入版本库
二、重要命令
获得版本库
git init 初始化仓库
git clone 远程版本库clone至本地
查看信息
git help 获取帮助信息
git log 查看提交日志
git status 查看git信息
git diff 比较文件差别
版本管理
git add 将当前已修改的文件添加至暂存区
git commit 将暂存区的文件提交到git版本库中
git rm 删除版本库中特定的文件
远程协作
git pull 将远程版本库的文件拉取到本地
git push 将本地的版本信息推送至远程
配置git
git config
对于userName和userEmail来说,有三个地方可以配置
1. /etc/gitconfig(修改整个计算机)----》git config --system
2. ~/.gitconfig (修改计算机中不同用户)----》git config --global
3. 针对特定项目的,.git/config文件中----》 git config --local
基本操作
在桌面新建mygit文件夹,将此文件夹纳入git控制。
cmd 进入此文件夹
输入 git init
控制台打印如下:
Initialized empty Git repository in C:/Users/shz/Desktop/mygit/.git/
在mygit文件夹下,git会新建一个.git隐藏文件夹。此文件夹中的文件不能手动更改。
windows控制台 输入dir会查看当前文件夹下的文件
进入.git文件夹,输入dir 回车控制台打印
2019/01/29 14:21 130 config
2019/01/29 14:21 73 description
2019/01/29 14:21 23 HEAD
2019/01/29 14:21 <DIR> hooks
2019/01/29 14:21 <DIR> info
2019/01/29 14:21 <DIR> objects
2019/01/29 14:21 <DIR> refs
在mygit文件夹下,新建文件test.txt,查看状态。
windows控制台 新建空文件的命令是type nul->test.txt
此时git status查看状态
控制台输出如下:
On branch master//当前的分支
Initial commit//当前的提交信息
Untracked files://没有被纳入暂存区的文件
(use "git add <file>..." to include in what will be committed)//使用add命令将文件纳入暂存区以提交
test.txt//修改文件
nothing added to commit but untracked files present (use "git add" to track)//没有提交但是有未存入暂存区的文件
将文件test.txt提交至暂存区,查看状态
使用git add命令
git add test.txt 然后git status查看状态
控制台输出如下:
On branch master //当前的分支
Initial commit //当前的提交信息
Changes to be committed: //待提交的改变
(use "git rm --cached <file>..." to unstage) //使用git rm --cached 将文件从暂存区移除
new file: test.txt //新文件
将暂存区的test.txt文件从暂存区移除,查看状态
使用git rm --cached
git rm --cached test.txt 然后git status查看状态
控制台输出如下:
On branch master//当前的分支
Initial commit//当前的提交
Untracked files://为加入暂存区的文件
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)//存在未加入暂存区的文件
git commit
如果只输入 git commit 命令会进入vim编辑模式
window控制vim编辑模式
键盘i 会进入编辑模式
键盘esc 会退出编辑模式
输入大写的Z 会保存退出
git commit -m "注释" 会将修改文件存入暂存区
如果注释为空的话
控制台会输出如下:
Aborting commit due to empty commit message.//由于注释为空,遗弃本次commit
git commit -m "initial commit"
控制台会输出如下:
[master (root-commit) 2908168] initial commit //提交信息
1 file changed, 1 insertion(+) //一个文件改变,改变是插入一行
create mode 100644 test.txt //显示提交文件和模式
此时git status
控制台会输出如下:
On branch master //当前的分支
nothing to commit, working tree clean //没有待提交的文件 是clean
此时git log //打印提交信息 倒序
控制台会输出如下:
commit 2908168c8eab3dcff75f7499d7b59b5be470b285 //提交id
Author: //用户名
Date: //时间
initial commit //提交信息
修改文件,并查看add 、commit信息
windows控制修改文件 echo xxxx >>文件名
echo hello >>test.txt //文件已修改
git status
控制台打印如下:
On branch master //当前的分支
Changes not staged for commit://有改变没有提交至暂存区
(use "git add <file>..." to update what will be committed)//使用git add命令修改待提交文件
(use "git checkout -- <file>..." to discard changes in working directory)//使用git checkout将文件的改变遗弃
modified: test.txt //修改的文件
no changes added to commit (use "git add" and/or "git commit -a")
git checkout -- test.txt //文件还原
后续的git add test.txt
git commit -m "注释"
网友评论