GitHub入门与实践(2)掌握Git 1、基本操作
来源:互联网 发布:python安装在d盘 编辑:程序博客网 时间:2024/05/29 17:18
1、基本操作
1)初始化仓库
git int
<span style="white-space:pre"></span>$ mkdir git-tutorial<span style="white-space:pre"></span>$ cd git-tutorial/<span style="white-space:pre"></span>$ git init<span style="white-space:pre"></span>Initialized empty Git repository in c:/Documents and Settings/Administrator/Hello_World/git-tutorial/.git/
2)查看仓库的状态
git status
<span style="white-space:pre"></span>$ git status<span style="white-space:pre"></span># On branch master<span style="white-space:pre"></span>#<span style="white-space:pre"></span># Initial commit<span style="white-space:pre"></span>#<span style="white-space:pre"></span>nothing to commit (create/copy files and use "git add" to track) <span style="white-space:pre"></span>$ touch README.md<span style="white-space:pre"></span>$ git status<span style="white-space:pre"></span># On branch master<span style="white-space:pre"></span>#<span style="white-space:pre"></span># Initial commit<span style="white-space:pre"></span>#<span style="white-space:pre"></span># Untracked files:<span style="white-space:pre"></span># (use "git add <file>..." to include in what will be committed)<span style="white-space:pre"></span>#<span style="white-space:pre"></span># README.md<span style="white-space:pre"></span>nothing added to commit but untracked files present (use "git add" to track)
3)向暂存区中添加文件
git add
<span style="white-space:pre"></span>$ git add README.md <span style="white-space:pre"></span>$ git status<span style="white-space:pre"></span># On branch master<span style="white-space:pre"></span>#<span style="white-space:pre"></span># Initial commit<span style="white-space:pre"></span>#<span style="white-space:pre"></span># Changes to be committed:<span style="white-space:pre"></span># (use "git rm --cached <file>..." to unstage)<span style="white-space:pre"></span>#<span style="white-space:pre"></span># new file: README.md<span style="white-space:pre"></span>#
4)保存仓库的历史记录
git commit
<span style="white-space:pre"></span>$ git commit -m "First commit"<span style="white-space:pre"></span>[master (root-commit) 3f9014e] First commit<span style="white-space:pre"></span>1 file changed, 0 insertions(+), 0 deletions(-)<span style="white-space:pre"></span>create mode 100644 README.md<span style="white-space:pre"></span>$ git status<span style="white-space:pre"></span># On branch master<span style="white-space:pre"></span>nothing to commit, working directory clean
5)查看提交日志
git log
<span style="white-space:pre"></span>$ git log<span style="white-space:pre"></span>commit 3f9014e2b31071d17f6d6d5ce144780a2e0dbf13<span style="white-space:pre"></span>Author: Wu Jian <Jamsonwoo@126.com><span style="white-space:pre"></span>Date: Fri Feb 12 22:17:23 2016 +0800<span style="white-space:pre"></span> First commit <span style="white-space:pre"></span># 只显示提交信息的第一行<span style="white-space:pre"></span>$ git log --pretty=short<span style="white-space:pre"></span>commit 3f9014e2b31071d17f6d6d5ce144780a2e0dbf13<span style="white-space:pre"></span>Author: Wu Jian <Jamsonwoo@126.com><span style="white-space:pre"></span> First commit<span style="white-space:pre"></span># 只显示指定目录、文件的日志<span style="white-space:pre"></span>$ git log README.md<span style="white-space:pre"></span>commit 3f9014e2b31071d17f6d6d5ce144780a2e0dbf13<span style="white-space:pre"></span>Author: Wu Jian <Jamsonwoo@126.com><span style="white-space:pre"></span>Date: Fri Feb 12 22:17:23 2016 +0800<span style="white-space:pre"></span> First commit<span style="white-space:pre"></span># 显示文件的改动<span style="white-space:pre"></span>$ git log -p<span style="white-space:pre"></span>$ git log -p README.md<span style="white-space:pre"></span>commit 3f9014e2b31071d17f6d6d5ce144780a2e0dbf13<span style="white-space:pre"></span>Author: Wu Jian <Jamsonwoo@126.com><span style="white-space:pre"></span>Date: Fri Feb 12 22:17:23 2016 +0800 <span style="white-space:pre"></span> First commit<span style="white-space:pre"></span>diff --git a/README.md b/README.md<span style="white-space:pre"></span>new file mode 100644<span style="white-space:pre"></span>index 0000000..e69de29
6)查看更改前后的差别
git diff
<span style="white-space:pre"></span>$ git diff<span style="white-space:pre"></span>diff --git a/README.md b/README.md<span style="white-space:pre"></span>index e69de29..f2eddc2 100644<span style="white-space:pre"></span>--- a/README.md<span style="white-space:pre"></span>+++ b/README.md<span style="white-space:pre"></span>@@ -0,0 +1 @@<span style="white-space:pre"></span>+# Git<BD>̳<CC><span style="white-space:pre"></span>\ No newline at end of file <span style="white-space:pre"></span>$ git add README.md<span style="white-space:pre"></span>$ git diff HEAD<span style="white-space:pre"></span>diff --git a/README.md b/README.md<span style="white-space:pre"></span>index e69de29..f2eddc2 100644<span style="white-space:pre"></span>--- a/README.md<span style="white-space:pre"></span>+++ b/README.md<span style="white-space:pre"></span>@@ -0,0 +1 @@<span style="white-space:pre"></span>+# Git<BD>̳<CC><span style="white-space:pre"></span>\ No newline at end of file
0 0
- GitHub入门与实践(2)掌握Git 1、基本操作
- GitHub入门与实践(2)掌握Git 2、分支操作
- GitHub入门与实践(2)掌握Git 3、更改提交操作
- GitHub入门与实践(2)掌握Git 6、Git学习资料
- GitHub入门与实践(2)掌握Git 4、推送至远程仓库
- GitHub入门与实践(2)掌握Git 5、从远程仓库获取
- GitHub入门与实践学习笔记--github学习基础之关于git的基本操作
- GitHub入门与实践(四)——Git的基本操作从初始化仓库到确认提交是否成功
- Git与github基本操作
- Git与github基本操作
- GitHub入门与实践(三)——初步体验Git与GitHub的联动
- 虚拟项目学习git/github原理与基本操作2
- 虚拟项目学习git/github原理与基本操作1
- (1) git/github原理与基本操作ABC中的ABC
- git与github的基本操作
- GitHub入门与实践(1)GitHub 前期准备
- GitHub入门与实践
- 《GitHub入门与实践》
- MD5函数
- PHP加密函数
- 水题
- 扩展欧几里得的学习
- 新中国休假制度变迁:曾经每周只休息一天
- GitHub入门与实践(2)掌握Git 1、基本操作
- 【黑马程序员Android自学笔记】62期-26天-安卓基础 — 电话拨号器
- 【慕课笔记】U4 多态 第6节 综合练习
- 河南第六届ACM省赛(异 形 卵)
- 票据的概念和种类
- 置换专题
- 1032. Sharing (25)
- bzoj2186【SDOI2008】沙拉公主的困惑
- mycat 连续分片 -> 自定义数字范围分片