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 工具的作用也不仅仅只是单纯的对同一个版本进行管理 ...
随机推荐
- CSS性能优化的8个技巧
本文作者:高峰,360奇舞团前端工程师,W3C性能工作组成员,同时参与WOT工作组的学习. 我们都知道对于网站来说,性能至关重要,CSS作为页面渲染和内容展现的重要环节,影响着用户对整个网站的第一体验 ...
- C# 核心基础(1) 持续更新
using System; namespace ConsoleApplicationCShape { class Program { static void Main(string[] args) { ...
- nginx 之 root和alias
转载: https://www.jianshu.com/p/4be0d5882ec5 https://blog.csdn.net/Erica_1230/article/details/7855311 ...
- Microsoft.Practices.Unity使用配置文件总是报错The type name or alias could not be resolved.
Type name could not be resolved. Please check config file http://stackoverflow.com/questions/1493564 ...
- luogu P2585 [ZJOI2006]三色二叉树
P2585 [ZJOI2006]三色二叉树 题目描述 输入输出格式 输入格式: 输入文件名:TRO.IN 输入文件仅有一行,不超过10000个字符,表示一个二叉树序列. 输出格式: 输出文件名:TRO ...
- 【CUDA 基础】6.5 流回调
title: [CUDA 基础]6.5 流回调 categories: - CUDA - Freshman tags: - 流回调 toc: true date: 2018-06-20 21:56:1 ...
- HTML/HTML5 知识点思维导图
1 - 浏览器 | 浏览器页面构成 2 - 浏览器 | 浏览器内核相关知识点 3 - W3C | 对WEB标准以及W3C的理解与认识? 4 - 标签 | Doctype相关知识点 5 - 标签 | m ...
- Java后台开发精选知识图谱
1.引言: 学习一个新的技术时,其实不在于跟着某个教程敲出了几行.几百行代码,这样你最多只能知其然而不知其所以然,进步缓慢且深度有限,最重要的是一开始就对整个学习路线有宏观.简洁的认识,确定大的学习方 ...
- Asyncio之EventLoop笔记
使用事件循环 Python3.4 采用了一个强大的框架来支持代码的并发执行: asyncio.这个框架使用事件循环来编排回调和异步任务. 事件循环位于事件循环策略的上下文中-这是 asyncio 所特 ...
- 2018-2019-2 20175226王鹏雲 实验四《Android程序设计》实验报告
2018-2019-2 20175226王鹏雲 实验四<Android程序设计>实验报告 实验报告封面 课程:Java程序设计 班级:1752班 姓名:王鹏雲 学号:20175226 指导 ...