来到git bash界面
1.查看当前路径
pwd //输出 /e/demo 我现在在E盘下的demo文件夹
2.显示所有文件的详细信息
ll //输出 total 1
// -rw-r--r-- 1 admin 197121 32 Jun 12 21:53 test.txt
3.创建并进入文件夹
mkdir demo2
cd demo2
4.初始化仓库
git init //输出 Initialized empty Git repository in E:/demo/demo2/.git/
5.追加文字(无文件则创建)到文件末尾
echo "demo reposi" >> test.txt
6.查看文件内容
cat test.txt //输出 demo reposi
7.添加文件到暂存区
git add test.txt
//输出
//warning: LF will be replaced by CRLF in test.txt.
//The file will have its original line endings in your working directory.
8.提交暂存区的文件到仓库并添加提交信息
git commit test.txt -m "test first commit"
//输出
//warning: LF will be replaced by CRLF in test.txt.
//The file will have its original line endings in your working directory.
//[master (root-commit) 0be2f76] test first commit
// 1 file changed, 1 insertion(+)
//create mode 100644 test.txt
9.查看文件状态
git status
//输出 文件提交到master分支,无操作,工作是clean干净的
//On branch master
//nothing to commit, working tree clean
10.文件内容回滚并确认
git reset HEAD test.txt
//输出 注意,此时并未完成回滚,需要下一操作
//git reset HEAD demo.txt
//Unstaged changes after reset:
//M test.txt
//查看一下此时的状态
git status
//On branch master
//Changes not staged for commit:
// (use "git add <file>..." to update what will be committed)
// (use "git checkout -- <file>..." to discard changes in working directory)
// modified: test.txt
//no changes added to commit (use "git add" and/or "git commit -a")
git checkout -- test.txt
//此时文件已回到上次提交的状态,可打开查看
git status
//On branch master
//nothing to commit, working tree clean
11.放弃本次提交,回滚到某一次提交的状态
git log //查看所有提交的commit 号,并找到要回滚的commit号
//commit 433db8b415782d36df1cee767156a457be8c69cd
//Author: sakura <2399865721@qq.com>
//Date: Wed Jun 12 22:20:28 2019 +0800
// second commit
//commit 0be2f763dbabb6fb5aace90c154ff97fc5516589
//Author: sakura <2399865721@qq.com>
//Date: Wed Jun 12 22:05:11 2019 +0800
// test first commit
git reset --hard 0be2f763dbabb6fb5aace90c154ff97fc5516589
//hard指仓库和暂存区都进行回滚
//HEAD is now at 0be2f76 test first commit
//此时文件已恢复
12.删除文件
git rm test.txt //此时并未删除,需下一步
//rm 'test.txt'
git commit -m "delete test"
//[master 71b5719] delete test
// 1 file changed, 1 deletion(-)
// delete mode 100644 test.txt
13.标签管理
便于回滚,使用便签可回滚到指定标签的状态
git tag //查看所有标签
git tag tagname //创建标签
git tag -a name -m "content" //指定提交标签
git tag -d name //删除标签
git push origin name //标签发布
14.分支管理
git不止只有一个master分支,可自己创建分支,后将分支合并到master中去
git branch //查看所有分支
git branch new_branch //创建分支
git checkout branch_name //切换分支
git merge branch_name //合并分支
git branch -d branch_name//删除分支
15.添加远程仓库
git remote add origin git@github.com:qiujiakang120/sakura_test.git
//后边是仓库链接
git push -u origin master
//推送到远程
16.克隆仓库
git clone git@github.com:qiujiakang120/sakura_test.git
//后边是仓库链接
git push -u origin master
//推送到远程