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 工具的作用也不仅仅只是单纯的对同一个版本进行管理 ...
随机推荐
- Hive的JDBC连接
首相要安装好hive 1.首先修改配置文件文件为hive 路径下的 conf/hive-sit.xml 将内容增加 <property> <name>hive.server2 ...
- macOS关闭修改扩展名的提示
关闭 defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false; killall Finder 开启 def ...
- org.apache.commons.io.FilenameUtils 常用的方法
/** * getExtension * 获取文件的后缀名 */ public static void testGetExtension() { String extension = Filename ...
- C# params object[] args 可以传多个参数,可以不限制类型
http://blog.csdn.net/wslyy99/article/details/1836486 C#参数数组(params)的使用方法 http://www.vcsos.com/articl ...
- [CTS2019]田野(80分)
loj嘟嘟嘟 学完模拟退火后开始搞这道题,搞了一下午最终搞到了80分,剩下的实在不知道怎么办了-- 首先肯定是把有交点的线段划分到一个集合,然后对每一个集合求一遍凸包. 然后两两合并,如果新的凸包的周 ...
- socketserver(多连接)
正如前面的socket模块部分看到的一样,写一个简单套接字服务器不是很难,如果想实现超出继承的应用,最好寻求一些帮助,socketserver模块是标准库中很多服务器框架的基础,这些服务器架构包括Ba ...
- C++ 仿函数和适配器
本文从不断复杂的应用场景入手,来说明C++设计仿函数和适配器的原因,并深入源码来介绍仿函数和适配器的使用方法. 仿函数 现有一个vector,需要统计大于8的元素个数. 使用std::count_if ...
- ArcGIS Python根据的点坐标,创建点要素
import arcpy # A list of coordinate pairs # pointList = [[1,2],[3,5],[7,3]] # Create an empty Point ...
- HearthBuddy遇奥秘解决方法
https://tieba.baidu.com/g/5808796816 链接: https://pan.baidu.com/s/1NPQTOfxbN_4alP7J-XWuVw 密码: xfj1
- EBS登录问题小结
1 网络问题 1)ping IP 2)telnet IP 端口 备注:如果端口能访问则直接跳转,如果不能访问则报错如下所示: 2)配置host文件 如果访问的服务器在内网,则需要配置host信息 3) ...