1、版本的查询
git --version
2、管理信息
git config --global user.name "yngaoyan"
git config --global user.emil "yngaoyan@gmail.com"
3、文件提交
(1)在文件夹中创建目录文件
mkdir 目录名
git init 初始化文件
ehco aaa >xx.txt 或 echo bbb >>xx.txt写入内容
当输入 echo ccc >xx.txt 时会覆盖原来的内容
(touch xx.txt 建立空白文件)
type xx.txt 查看文件中的内容
type * 查看文件中的所有内容,包括文件里面含有的内容
(2)查看文件状态
git status 或 git status -s
当显示以下内容时说明文件还在暂存区中,还没提交到工厂
Untracked files:
(use "git add <file>..." to include in what will be committed)
xx.txt
(3)文件添加
① git add xx.txt (添加某一个文件)
git add . (提交所有文件给暂存区)
查看状态当显示以下内容时,说明已经添加
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: xx.txt
② git commit -m “first” (来进行提交)
显示以下内容说明提交成功
[master (root-commit) 2b45491] first
3 files changed, 7 insertions(+)
create mode 100644 a.txt
create mode 100644 b.txt
create mode 100644 c.txt
③ git log(来查看版本)
commit 2b454916d1499988ea16b8ee99bcfafeb4ff70e3
Author: yngaoyan <yngaoyan@gemil.com>
Date: Fri Apr 21 18:08:53 2017 +0800
//如果版本太多显示不完,会出现分号,可以使用以下命令来简写
git log --pretty=online
4、文件的版本还原
git reset --hard 2b4549
HEAD is now at 2b45491
/*2b4549 是要还原的版本号*/
git checkout xx.txt (在文件还没有提交之前,可以还原到上一版本) //只有文件还没有提交才能还原,提交后就不能还原
git reset HEAD xx.txt (将文件还原到xx.txt的版本)
git update-ref refs/INIT/2b4549
git reset --hard INIT
5、文件的删除
rm -rf xx.txt (删除在目录中的某一个文件)
rm -rf* (删除所有目录中的文件)
git rm --cached xx.txt(删除已经提交后的暂存区的目录,此时暂存区中的index时间改变)
git 的文件有以下四种状态:
Untracked
Unmodified
Modified
Staged
6、分支管理
创建的新分支只能看见上一个分支的内容,在新分支上创建子分支时,子分支不能看见第一个分支,只能看见在当前的上一个分支
git branch 查看分支
git branch b1 添加分支
git branch -d b1 删除分支
git merge b1 合并分支
git checkout -b b1 建分支并切换分支
git checkout -b b1 master 在master的基础上创建b1分支
git checkout xxx 切换到某一个分支
网友评论