博客园测试第二篇

Git 实践

本文为测试markdown效果,无其他用途。

1、克隆远程仓库

zhangy@Liuying-PC MINGW64 ~
$ git clone http://gitlab.cqrd.com/yingliu/efront.git
Cloning into 'efront'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.

2、查看状态

zhangy@Liuying-PC MINGW64 ~
$ cd efront

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

3、创建文件夹及文件

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ mkdir git

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ cd git

zhangy@Liuying-PC MINGW64 ~/efront/git (master)
$ vi git.basic.md

4、再次查看状态

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ ll
total 1
drwxr-xr-x 1 zhangy 197121 0 四月 10 07:35 git/
-rw-r--r-- 1 zhangy 197121 8 四月 10 07:26 README.md

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

       git/

nothing added to commit but untracked files present (use "git add" to track)

5、将文件添加到git暂存区,以便git跟踪

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git add git

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   git/git.basic.md

6、提交文件到本地仓库

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git commit -m "add files"
[master 2f7bbbb] add files
 1 file changed, 9 insertions(+)
 create mode 100644 git/git.basic.md

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)
nothing to commit, working directory clean

7、推送文件到远程仓库

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git push --set-upstream origin master
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 496 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To http://gitlab.cqrd.com/yingliu/efront.git
   4faf842..2f7bbbb  master -> master
Branch master set up to track remote branch master from origin.

8、查看历史

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git log
commit 2f7bbbb2dfafcb48df366f3c6bb9d37d92469e5f
Author: liuying <yingliu@travelsky.com>
Date:   Mon Apr 10 15:41:48 2017 +0800

    add files

commit 4faf842df2ece6619714a0b8ba23c539f8107254
Author: liuying <090854dummy@test.com>
Date:   Wed Mar 8 14:50:33 2017 +0800

    efront拉

9、从远程仓库抓取数据

zhangy@Liuying-PC MINGW64 ~
$ cd efront

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From http://gitlab.cqrd.com/yingliu/efront
   2f7bbbb..f49aa28  master     -> origin/master
Updating 2f7bbbb..f49aa28
Fast-forward
 git/README.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 git/README.md
zhangy@Liuying-PC MINGW64 ~/efront (master)
$ ls git
    git.basic.md  README.md

10、在本地git目录下修改一个文件

    在本地git目录下修改 README.md,增加的内容是: git diff HEAD

11、查看工作空间与本地库之间的差异

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git diff HEAD
diff --git a/git/README.md b/git/README.md
index bddc158..d851a31 100644
--- a/git/README.md
+++ b/git/README.md
@@ -1 +1 @@
-git pull
\ No newline at end of file
+git diff HEAD
\ No newline at end of file

12、将修改的文件添加到暂存区,以便跟踪

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/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:   git/README.md

no changes added to commit (use "git add" and/or "git commit -a")

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git add -A

13、查看暂存区与本地库之间的差异

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git diff --staged
diff --git a/git/README.md b/git/README.md
index bddc158..d851a31 100644
--- a/git/README.md
+++ b/git/README.md
@@ -1 +1 @@
-git pull
\ No newline at end of file
+git diff HEAD
\ No newline at end of file

14、重置暂存区中的文件

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git reset git/README.md
Unstaged changes after reset:
M       git/README.md

15、将工作区的文件还原到修改之前

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/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:   git/README.md

no changes added to commit (use "git add" and/or "git commit -a")

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git checkout -- git/README.md

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

16、创建并切换分支

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git branch dev

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git checkout dev
Switched to branch 'dev'

17、推送新的分支到远程仓库

zhangy@Liuying-PC MINGW64 ~/efront (dev)
$ git push --set-upstream origin dev
Total 0 (delta 0), reused 0 (delta 0)
To http://gitlab.cqrd.com/yingliu/efront.git
 * [new branch]      dev -> dev
Branch dev set up to track remote branch dev from origin.

18、删除当前分支上的文件

zhangy@Liuying-PC MINGW64 ~/efront (dev)
$ git rm '*.md'
rm 'README.md'
rm 'git/README.md'
rm 'git/git.basic.md'

19、提交修改到当前分支

zhangy@Liuying-PC MINGW64 ~/efront (dev)
$ git commit -m "Remove all the cats"
[dev 5b96906] Remove all the cats
 3 files changed, 11 deletions(-)
 delete mode 100644 README.md
 delete mode 100644 git/README.md
 delete mode 100644 git/git.basic.md

20、切换到master分支

zhangy@Liuying-PC MINGW64 ~/efront (dev)
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

21、合并dev分支

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git merge dev
Updating f49aa28..5b96906
Fast-forward
 README.md        | 1 -
 git/README.md    | 1 -
 git/git.basic.md | 9 ---------
 3 files changed, 11 deletions(-)
 delete mode 100644 README.md
 delete mode 100644 git/README.md
 delete mode 100644 git/git.basic.md

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ ls

22、删除分支

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git branch -d dev
warning: not deleting branch 'dev' that is not yet merged to
         'refs/remotes/origin/dev', even though it is merged to HEAD.
error: The branch 'dev' is not fully merged.
If you are sure you want to delete it, run 'git branch -D dev'.

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git branch -D dev
Deleted branch dev (was 5b96906).

23、推送文件到远程仓库

zhangy@Liuying-PC MINGW64 ~/efront (master)
$ git push
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (1/1), done.
Writing objects: 100% (2/2), 200 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To http://gitlab.cqrd.com/yingliu/efront.git
   f49aa28..5b96906  master -> master
posted @ 2017-04-10 17:11  颖颖颖  阅读(295)  评论(0编辑  收藏  举报