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