Git 创建仓库

执行<git init>命令后,Git仓库会生成一个.git目录,该目录包含了资源的所有元数据,其他的项目目录保持不变(Git 只在仓库的根目录生成 .git 目录)。

使用当前目录作为Git仓库

$git init

使用指定目录作为Git仓库

$git init <directory>

使用<git clone>从Git仓库中拷贝项目。

克隆仓库

$git clone <remote repository>

克隆到指定的目录

$git clone <remote repository> <local directory>
admin MINGW64 /
$ cd c admin MINGW64 /c
$ mkdir GitRepositoryTest admin MINGW64 /c
$ cd GitRepositoryTest/ admin MINGW64 /c/GitRepositoryTest
$ git init test1
Initialized empty Git repository in C:/GitRepositoryTest/test1/.git/ admin MINGW64 /c/GitRepositoryTest
$ ls
test1/ admin MINGW64 /c/GitRepositoryTest
$ git git clone git@github.com:lyz170/DesignPattern.git DesignPattern
Cloning into 'DesignPattern'...
remote: Counting objects: 7132, done.
remote: Compressing objects: 100% (558/558), done.
remote: Total 7132 (delta 6541), reused 7065 (delta 6498)
Receiving objects: 100% (7132/7132), 1.84 MiB | 0 bytes/s, done.
Resolving deltas: 100% (6541/6541), done.
Checking connectivity... done.
Checking out files: 100% (2902/2902), done. admin /c/GitRepositoryTest
$ ls
DesignPattern/ test1/

<例>

Git add/status/diff/commit/reset/remove/move

<git add>命令可将该文件添加到缓存([.]整个目录add)

$git add <file name> <file name> [.]

<git status>以查看在你上次提交之后是否有修改及文件状态 (-s:简短输出)

[A]表示已缓存

[AM]表示文件在将它添加到缓存之后又有改动,需要再使用git add后才会变成[A]

$git status [-s]
admin MINGW64 /c/GitRepositoryTest
$ ls
DesignPattern/ test1/ admin MINGW64 /c/GitRepositoryTest
$ cd test1/ admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ cp -p file1 file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ ls
file1 file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
?? file1
?? file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git add file1 file2
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
A file1
A file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
AM file1
A file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git add file1
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
A file1
A file2

<例>

<git diff>命令显示已写入缓存与已修改但尚未写入缓存的改动的区别(default:当前目录下所有尚未缓存的改动  [--cached]:查看已缓存的改动  [--stat]:显示摘要而非整个diff  [<file name>]查看具体某个文件而非整个目录)

$git diff [--cached] [--stat] [<file name>]
admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
AM file1
A file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git diff
diff --git a/file1 b/file1
index 1ebef96..d01e930 100644
--- a/file1
+++ b/file1
@@ -1,2 +1,3 @@
'file1' was created at 2017-8-31 16:52:00
'file1' was updated at 2017-8-31 16:57:00
+'file1' was updated at 2017-8-31 17:37:00
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git diff --stat
file1 | 1 +
1 file changed, 1 insertion(+)
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git diff --cached file2
diff --git a/file2 b/file2
new file mode 100644
index 0000000..baa67ac
--- /dev/null
+++ b/file2
@@ -0,0 +1 @@
+'file2' was created at 2017-8-31 16:53:00
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory.

<例>

<git commit>将缓存区内容添加到仓库中(default:强制写入提交comment  [-m 'XXX']:可以在命令行中写comment  [-a]:跳过<git add>提交缓存的流程直接提交)

$git commit [-m] [-a]
admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git add file2
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git commit -m 'commited by lyz'
[master warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory.
1166cb5] commited by lyz
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+) admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status
On branch master
nothing to commit, working directory clean admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git commit -am 'commited by lyz'
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory.
[master warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory.
944283e] commited by lyz
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory.
1 file changed, 1 insertion(+) admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status
On branch master
nothing to commit, working directory clean

<例>

<git reset HEAD 命令用于取消已缓存的内容(default:取消目录下已缓存的所有文件  [ -- <file name>] 取消其中一个的缓存)

$git reset HEAD [ -- <file name>]
admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ vi file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
M file1
M file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git reset HEAD
Unstaged changes after reset:
M file1
M file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
M file1
M file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git add .
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git reset HEAD -- file1
warning: LF will be replaced by CRLF in file1.
The file will have its original line endings in your working directory.
Unstaged changes after reset:
M file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory.
M file1
M file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git reset HEAD
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory.
Unstaged changes after reset:
M file1
M file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
M file1
M file2

<例>

<git rm <file name>>会将条目从缓存区中移除。这与<git reset HEAD>将条目取消缓存是有区别的。后者是将缓存区恢复为我们做出修改之前的样子。前者会将文件从缓存区和你的硬盘中(工作目录)删除。([--cached]在工作目录中留着该文件)

$git rm [--cached] <file name>
admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git rm file1
rm 'file1' admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ ls
file2 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git rm --cached file2
rm 'file2' admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
D file1
D file2
?? file2

<例>

<git mv <old file name> <new file name>>命令用于移动或重命名一个文件、目录、软连接

$git mv <old file name> <new file name>
admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git add file2
warning: LF will be replaced by CRLF in file2.
The file will have its original line endings in your working directory. admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
D file1 admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git mv file2 file2new admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ ls
file2new admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status -s
D file1
R file2 -> file2new admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git commit
[master e6c8a62] commit
warning: LF will be replaced by CRLF in file2new.
The file will have its original line endings in your working directory.
2 files changed, 5 deletions(-)
delete mode 100644 file1
rename file2 => file2new (100%) admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ git status
On branch master
nothing to commit, working directory clean admin MINGW64 /c/GitRepositoryTest/test1 (master)
$ ls
file2new

Git(2):基本操作的更多相关文章

  1. Git GUI基本操作

    一.Git GUI基本操作 1.版本库初始化 gitpractise文件夹就变成了Git可以管理的仓库,目录下多了一个.git文件夹,此目录是Git用于管理版本库的,不要擅自改动里面的文件,这样会破坏 ...

  2. 【转】Git GUI基本操作

    一.Git GUI基本操作 1.版本库初始化 gitpractise文件夹就变成了Git可以管理的仓库,目录下多了一个.git文件夹,此目录是Git用于管理版本库的,不要擅自改动里面的文件,这样会破坏 ...

  3. Git&Github基本操作与分支管理

    Git的原理涉及快照流.链表.指针等,这里不作过多叙述. 1.基本操作 git init 创建一个 Git 仓库 git clone [url] 拷贝一个 Git 仓库到本地 git add [fil ...

  4. Git/GitHub基本操作

    GitGit是分布式版本控制工具,SVN是集中式版本控制,有单点故障的问题GitHub是Git的代码托管中心,类似的国内有码云,是远程维护库Git的优势大部分操作在本地完成,不需要联网完整性有保证尽可 ...

  5. Git命令基本操作

    本文从以下九个方面,介绍Git命令的基本操作: 一. Git安装 二. Git基本配置 三. 创建Git仓库 四. 获得Git仓库 五. 提交更新 六. 提交历史查看 七. 远程仓库 八. 打Tags ...

  6. 【Git的基本操作三】基本操作命令

    基本操作 (1) 状态查看操作 git status 作用:查看工作区.暂存区状态 (2) 添加操作 git add [filename] 作用:将工作区文件的 添加/修改,添加到暂存区 (3) 提交 ...

  7. Git分支基本操作

    感谢廖雪峰老师,以下教程均来自廖雪峰老师的博客,地址:https://www.liaoxuefeng.com/wiki/896043488029600/900003767775424 基本原理 在版本 ...

  8. git的基本操作

    今天给同事培训了一下git的使用流程,简单记录一下 1,基本概念, 远程库和本地库. 2, git clone git://url/*.git clone远程的代码库到本地 3. 创建本地分支 当前是 ...

  9. Github学习之路-小试牛刀,练习Git 的基本操作

    一.下子windows客户端. Git 客户端下载地址:http://msysgit.github.io/ 二.打开Git Bash 命令行操作界面. 安装完成后,在开始菜单里找到“Git”-> ...

  10. 从VSS到SVN再到Git 记Git的基本操作

    Source code control 一直是软件开发过程中重要的环节,从最初的纯文件备份,到使用工具进行管理.Source code control 工具的作用也不仅仅只是单纯的对同一个版本进行管理 ...

随机推荐

  1. pyltp安装

    第一步:下载wheel文件 第二步:进入该文件的文件夹 第三步:pip install wheel文件名 注意:python的安装版本必须和pyltp的版本相同,我这版本都是pyhton3.6.之前p ...

  2. JavaScript 对象中this的指向问题

    this运行在哪个对象下,就指向哪个对象.

  3. BZOJ4886 [Lydsy1705月赛]叠塔游戏[基环树]

    很妙的一道题. 由于本人过于zz,不会这道题,通过厚颜无耻翻阅题解无数终于懂了这道题,所以这里转载一位神仙的blog. 没有看懂?没事,再来一篇. 这题个人认为主要在于转化题意和建图,这两点想通了应该 ...

  4. 详解Object.create(null)

    在Vue和Vuex的源码中,作者都使用了Object.create(null)来初始化一个新对象.为什么不用更简洁的{}呢? 在SegmentFault和Stack Overflow等开发者社区中也有 ...

  5. dockerfile-maven plugin自动镜像制作并发布

    环境准备:win10+docker 1.打开hyper-v 2.下载最新版本docker:https://store.docker.com/editions/community/docker-ce-d ...

  6. request.getParameterNames获得请求参数的名字(Get或者Post请求的参数都可以)

    1 protected Map<String, String> initRequestParams(HttpServletRequest request) { 2 Map<Strin ...

  7. 粗暴,干就完了----徐晓冬似的C语言自学笔记----前言

    10对年前就觉得C/C++语言很酷,第一印象就是90年代末,个人电脑在中华大地开始普及的岁月中,层出不穷的病毒,对了,全是C/C++写的:除了危及人民群众信息安全以外,C系列语言用途甚广,可以发明其他 ...

  8. offset([coordinates])

    offset([coordinates]) 概述 获取匹配元素在当前视口的相对偏移. 返回的对象包含两个整型属性:top 和 left,以像素计.此方法只对可见元素有效.大理石平台价格表 参数 coo ...

  9. JSP大文件分片上传

    核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...

  10. CSP-S 模拟53 题解

    题解: T1 u: 一看到修改这么多,但询问其实只有一个不难想到差分,但是他这个形状可以说很不规则,于是我们想到分别维护竖着的和斜着的差分,然后最后合并即可. 考场上瞎调了一波系数莫名AC,其实是维护 ...