码迷,mamicode.com
首页 > 其他好文 > 详细

文章标题

时间:2016-05-12 12:46:46      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

全局设置

$ git config user.email "xuym@travelsky.com"
$ git config user.name xuym
$ git config --global credential.helper store
$ git config --global core.autocrlf false

以上分别是邮箱,用户名,密码自动保存,禁止自动换行的设置

克隆远程仓库

$ git clone http://gitlab.cqrd.com/xuym/efront.git
Cloning into ‘efront‘...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

查看状态

$ cd efront

$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

创建文件夹及文件

$ mkdir git
$ cd git
$ mkdir start
$ cd start
$ mkdir git
$ cd git
$ vi git.basic.md

再次查看状态

$ cd ../../../
$ pwd
/f/efront
$ ll
total 0
drwxr-xr-x 1 admin 197121 0 五月 10 02:24 git/

$ 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)

将文件添加到git暂存区

$ git add git
$ 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/start/git/git.basic.md

提交文件到本地仓库

$ git commit -m "添加文件git/start/git/git.basic.md"
[master 5e9f74e] 添加文件git/start/git/git.basic.md
 1 file changed, 1 insertion(+)
 create mode 100644 git/start/git/git.basic.md

$ 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

推送文件到远程仓库

$ git push --set-upstream origin master
Username for ‘http://gitlab.cqrd.com‘: xuym
Password for ‘http://xuym@gitlab.cqrd.com‘:
Counting objects: 6, done.
Writing objects: 100% (6/6), 412 bytes | 0 bytes/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To http://gitlab.cqrd.com/xuym/efront.git
   ba08f19..5e9f74e  master -> master
Branch master set up to track remote branch master from origin.

查看历史

$ git log
commit 5e9f74e814d639ed4b0006b216c9d5c126e6ba37
Author: xuym <xuym@travelsky.com>
Date:   Tue May 10 10:48:54 2016 +0800

    添加文件git/start/git/git.basic.md

在gitlab上增加一个文件

使用页面编辑器在efront库的git目录下增加一个 README.md,里面的内容是: git pull

从远程仓库抓取数据

$ git pull
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), done.
From http://gitlab.cqrd.com/xuym/efront
   5e9f74e..fff4ff3  master     -> origin/master
Updating 5e9f74e..fff4ff3
Fast-forward
 git/start/git/README.md | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 git/start/git/README.md

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

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

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

$ git diff HEAD
diff --git a/git/start/git/README.md b/git/start/git/README.md
index bddc158..adbcb9d 100644
--- a/git/start/git/README.md
+++ b/git/start/git/README.md
@@ -1 +1,2 @@
-git pull
\ No newline at end of file
+git pull^M
+git diff HEAD
\ No newline at end of file

将修改的文件添加到暂存区

$ 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/start/git/README.md

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

admin@admin-PC MINGW64 /f/efront (master)
$ git add -A

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

$ git diff --staged
diff --git a/git/start/git/README.md b/git/start/git/README.md
index bddc158..adbcb9d 100644
--- a/git/start/git/README.md
+++ b/git/start/git/README.md
@@ -1 +1,2 @@
-git pull
\ No newline at end of file
+git pull^M
+git diff HEAD
\ No newline at end of file

重置暂存区中的文件,文件将从暂存区移出

$ git reset git/start/git/README.md
Unstaged changes after reset:
M       git/start/git/README.md

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

$ 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/start/git/README.md

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

$ git checkout --  git/start/git/README.md
$ git status
On branch master
Your branch is up-to-date with ‘origin/master‘.
nothing to commit, working directory clean

创建并切换分支

$ git branch dev
$ git checkout dev
Switched to branch ‘dev‘

推送新的分支到远程仓库

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

删除当前分支上的文件

$ git rm ‘*.md‘
rm ‘git/start/git/README.md‘
rm ‘git/start/git/git.basic.md‘

提交修改到当前分支

$ git commit -m "删除当前分支上所有文件"
[dev 7bf89ab] 删除当前分支上所有文件
 2 files changed, 2 deletions(-)
 delete mode 100644 git/start/git/README.md
 delete mode 100644 git/start/git/git.basic.md
$ git commit -m "删除当前分支上所有文件"
[dev 7bf89ab] 删除当前分支上所有文件
 2 files changed, 2 deletions(-)
 delete mode 100644 git/start/git/README.md
 delete mode 100644 git/start/git/git.basic.md

切换到master分支

$ git checkout master
Switched to branch ‘master‘
Your branch is up-to-date with ‘origin/master‘.

合并dev分支

$ git merge dev
Updating fff4ff3..7bf89ab
Fast-forward
 git/start/git/README.md    | 1 -
 git/start/git/git.basic.md | 1 -
 2 files changed, 2 deletions(-)
 delete mode 100644 git/start/git/README.md
 delete mode 100644 git/start/git/git.basic.md

删除分支

$ git branch -D dev
Deleted branch dev (was 7bf89ab).

推送文件到远程仓库,推送后,在gitlab网站中查看文件已经被删除

git push

获取版本并回退

$ git reflog
7bf89ab HEAD@{2}: merge dev: Fast-forward
fff4ff3 HEAD@{3}: checkout: moving from dev to master
7bf89ab HEAD@{4}: commit: 删除当前分支上所有文件
fff4ff3 HEAD@{5}: checkout: moving from master to dev
fff4ff3 HEAD@{6}: pull: Fast-forward
5e9f74e HEAD@{7}: commit: 添加文件git/start/git/git.basic.md
ba08f19 HEAD@{8}: commit: 删除文件
7a76ecb HEAD@{9}: commit: js数组
1e5d4e4 HEAD@{10}: commit: javascript数组测验
2926525 HEAD@{11}: pull: Fast-forward
6532730 HEAD@{12}: commit: home
15539c3 HEAD@{15}: commit (initial): my test
$ git reset --hard fff4ff3
HEAD is now at fff4ff3 创建文件README.md

文章标题

标签:

原文地址:http://blog.csdn.net/xuym123/article/details/51362535

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!