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 工具的作用也不仅仅只是单纯的对同一个版本进行管理 ...
随机推荐
- Jmeter - 命令行参数
同步更新至个人博客:https://njlife.top/2019/07/12/Jmeter-%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%8F%82%E6%95%B0/ Jmeter ...
- 0912 for循环及内置方法
目录 for 循环 1.循环 2.循环取值 3.range 4.for + break 5.for+continue 6.for + else 数字类型内置方法 整型 浮点型 字符串 1.作用 2.作 ...
- solr 中文分词相关(转载)
smartcn和ik的对比,来自http://www.cnblogs.com/hadoopdev/p/3465556.html 一.引言: 年的时候,就曾经有项目涉及到相关的应用(Lunce构建全文搜 ...
- MySQL主从同步、读写分离配置步骤、问题解决笔记
MySQL主从同步.读写分离配置步骤.问题解决笔记 根据要求配置MySQL主从备份.读写分离,结合网上的文档,对搭建的步骤和出现的问题以及解决的过程做了如下笔记: 现在使用的两台服务器已经 ...
- 4. CSS新特性之浏览器私有前缀
1. 浏览器私有前缀 浏览器私有前缀是为了兼容老版本的写法,比较新版本的浏览器无需添加 -moz-:代表firefox浏览器私有属性 -ms-:代表ie浏览器私有属性 -webkit-:代表safar ...
- springAOP分析
参考https://www.cnblogs.com/liuyk-code/p/9886033.html 在springboot中自动引入了配置文件AopAutoConfiguration @Confi ...
- Laravel中Contracts的理解和使用
Laravel 的 Contracts 是一组定义了框架核心服务的接口.说白了就是一组接口.使用它就是为了降低耦合性. 即便如此,是不是也有同学会搞不清楚Contracts在lavarel体系中的到底 ...
- Solution: The process cannot access the file [filename] because it is being used by another process.
http://www.brianstevenson.com/blog/solution-the-process-cannot-access-the-file-filename-because-it-i ...
- C# Socket 编程 Sample
使用Socket通信的服务器端编程,熟悉了服务器端和客户端的通信流程,实现了收发信息.文件传送以及震动功能 服务器端先创建Socket,然后将其和本地ip地址以及端口号连接,也就是使用Bind方法,然 ...
- Makefile(三)
在平时使用中,可以使用以下的makefile来编译单独的代码 src = $(wildcard *.c) obj = $(patsubst %.c, %.o, $(src)) CC = gcc CFL ...