Git(2):基本操作
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):基本操作的更多相关文章
- Git GUI基本操作
一.Git GUI基本操作 1.版本库初始化 gitpractise文件夹就变成了Git可以管理的仓库,目录下多了一个.git文件夹,此目录是Git用于管理版本库的,不要擅自改动里面的文件,这样会破坏 ...
- 【转】Git GUI基本操作
一.Git GUI基本操作 1.版本库初始化 gitpractise文件夹就变成了Git可以管理的仓库,目录下多了一个.git文件夹,此目录是Git用于管理版本库的,不要擅自改动里面的文件,这样会破坏 ...
- Git&Github基本操作与分支管理
Git的原理涉及快照流.链表.指针等,这里不作过多叙述. 1.基本操作 git init 创建一个 Git 仓库 git clone [url] 拷贝一个 Git 仓库到本地 git add [fil ...
- Git/GitHub基本操作
GitGit是分布式版本控制工具,SVN是集中式版本控制,有单点故障的问题GitHub是Git的代码托管中心,类似的国内有码云,是远程维护库Git的优势大部分操作在本地完成,不需要联网完整性有保证尽可 ...
- Git命令基本操作
本文从以下九个方面,介绍Git命令的基本操作: 一. Git安装 二. Git基本配置 三. 创建Git仓库 四. 获得Git仓库 五. 提交更新 六. 提交历史查看 七. 远程仓库 八. 打Tags ...
- 【Git的基本操作三】基本操作命令
基本操作 (1) 状态查看操作 git status 作用:查看工作区.暂存区状态 (2) 添加操作 git add [filename] 作用:将工作区文件的 添加/修改,添加到暂存区 (3) 提交 ...
- Git分支基本操作
感谢廖雪峰老师,以下教程均来自廖雪峰老师的博客,地址:https://www.liaoxuefeng.com/wiki/896043488029600/900003767775424 基本原理 在版本 ...
- git的基本操作
今天给同事培训了一下git的使用流程,简单记录一下 1,基本概念, 远程库和本地库. 2, git clone git://url/*.git clone远程的代码库到本地 3. 创建本地分支 当前是 ...
- Github学习之路-小试牛刀,练习Git 的基本操作
一.下子windows客户端. Git 客户端下载地址:http://msysgit.github.io/ 二.打开Git Bash 命令行操作界面. 安装完成后,在开始菜单里找到“Git”-> ...
- 从VSS到SVN再到Git 记Git的基本操作
Source code control 一直是软件开发过程中重要的环节,从最初的纯文件备份,到使用工具进行管理.Source code control 工具的作用也不仅仅只是单纯的对同一个版本进行管理 ...
随机推荐
- Java Listener
六. Java Listener 1. Java Listener 简介 * Java Listener 1. Java Listener(即:Java 监听器):用于监听 ServletRequ ...
- linux下top命令的使用
top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器 视图参数含义 top视图分为两部分:操作系统资源概况信息和进程信息.首先分析资源 ...
- BZOJ2278 [Poi2011]Garbage[欧拉回路求环]
首先研究环上性质,发现如果状态不变的边就不需要动了,每次改的环上边肯定都是起末状态不同的边且仅改一次,因为如果有一条边在多个环上,相当于没有改,无视这条边之后,这几个环显然可以并成一个大环.所以,我们 ...
- 前端知识体系:JavaScript基础-原型和原型链-理解原型设计模式以及 JavaScript中的原型规则
理解原型设计模式以及 JavaScript中的原型规则(原文地址) 1.原型对象:我们创建的每一个函数(JavaScript中函数也是一个对象)都有一个原型属性 prototype,原型属性实质上是一 ...
- flutter 项目中打印原生安卓的log信息
因为项目的需要 在flutter 中调用安卓的方法 再用安卓的方法去调用c写的so包 方法 如果当前项目下面没有android stduio 自带的logcat 那就利用下面的方法 在安卓代码中引入 ...
- 云主机用samba服务实现和windows共享文件
最近刚刚入坑了百度云的云主机BCC,准备在云主机上实现samba服务,映射到本机来当硬盘使用,可是一直怎么试都不成功,后来咨询客服之后才知道samba默认使用的端口445端口被运营商封禁了,只好更改端 ...
- LDA的参数确定和主题数确定方法
主题数确定:困惑度计算,画出曲线,选择拐点,避免信息丢失和主题冗余 https://blog.csdn.net/u014449866/article/details/80218054 参数调节: 方法 ...
- Educational Codeforces Round 33 (Rated for Div. 2) B题
B. Beautiful Divisors Recently Luba learned about a special kind of numbers that she calls beautiful ...
- removeClass([class|fn])
removeClass([class|fn]) 概述 从所有匹配的元素中删除全部或者指定的类.直线电机生产厂家 参数 classStringV1.0 一个或多个要删除的CSS类名,请用空格分开 f ...
- C# 父类代码动态转换子类
百度上搜索C# 如何父类运行时转换成子类,没有得到相应答案,突然想起C# 有dynamic类型试试看结果成功了... 以后编写代码类似这样的代码 就可以删减掉了 if (en.type == EMap ...