git 基本命令
来源:互联网 发布:png压缩 centos 编辑:程序博客网 时间:2024/06/08 11:21
安装
windows版Git 点击下载
安装完成后,需要最后一步设置,在命令行输入:
$ git config --global user.name "Your Name"$ git config --global user.email "email@example.com"
初始化仓库
先创建一个文件夹,我的是E盘下的learngit文件夹。然后在该目录下打开Git bash,用git init
初始化仓库
$ git initInitialized empty Git repository in E:/learngit/.git/
添加文件到仓库
添加文件到Git仓库,分两步:
第一步,使用命令git add
,注意,可反复多次使用,添加多个文件;
第二步,使用命令git commit
,完成。
添加一个txt文件:
$ git add readme.txt$ git commit -m "add a readme file"
添加多个文件夹示例:
$ git add file1.txt$ git add file2.txt file3.txt$ git commit -m "add 3 files."
查看工作区状态
修改txt内容比如增加一行。
Git is a distributed version control system.Git is a free software.Git is awesome.
运行 git status
:
$ git statusOn branch masterChanges not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: readme.txtno changes added to commit (use "git add" and/or "git commit -a")
上面的命令告诉我们,readme.txt被修改过了,但还没有准备提交的修改。
查看修改内容
如果git status
告诉你有文件被修改过,用git diff
可以查看修改内容。
$ git diffdiff --git a/readme.txt b/readme.txtindex 765e4af..bcc891a 100644--- a/readme.txt+++ b/readme.txt@@ -1,3 +1,5 @@ Git is a distributed version control system.-Git is a free software\ No newline at end of file+Git is a free software.++Git is awesome.\ No newline at end of file
版本回退
用git log
命令查看历史记录:
$ git logcommit 4a72e8bea77aba22d653b8c5aa9aea2bc6d2c4d4Author: adrianna1211 <adrianna243125587@gmail.com>Date: Mon Jul 11 15:06:04 2016 +0800 add a linecommit 0a20216c98c0d0d4d152bc2108e6ae01fe461f1eAuthor: adrianna1211 <adrianna243125587@gmail.com>Date: Mon Jul 11 14:56:04 2016 +0800 add distributedcommit db0647ca2b1cc758501985b2cda9520537c36785Author: adrianna1211 <adrianna243125587@gmail.com>Date: Mon Jul 11 14:50:26 2016 +0800 wrote a readme file
在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。
现在,我们要把当前版本“add a line”回退到上一个版本“add distributed”,就可以使用git reset
命令:
$ git reset --hard HEAD^HEAD is now at 0a20216 add distributed
也可以直接指定commit id来回退,id 可以不写全:
$ git reset --hard 0a202
版本回退撤销
还是用git reset
命令 ,需要目标commit id。
这就需要git reflog
查看命令历史,以获得commit id。以便确定要回到未来的哪个版本。
$ git reflog0a20216 HEAD@{0}: reset: moving to HEAD^4a72e8b HEAD@{1}: reset: moving to 4a72e0a20216 HEAD@{2}: reset: moving to HEAD^4a72e8b HEAD@{3}: commit: add a line0a20216 HEAD@{4}: commit: add distributeddb0647c HEAD@{5}: commit (initial): wrote a readme file
0 0
- 【Git】Git基本命令①
- GIT基本命令
- git 基本命令介绍
- git 基本命令
- git 基本命令介绍
- git 基本命令使用
- git 基本命令
- git 基本命令
- Git基本命令
- Git基本命令整理
- git基本使用命令
- Git操作基本命令
- git基本命令
- git基本命令
- git 基本命令介绍
- Git 基本命令
- git 基本命令
- git常用基本命令
- C语言入门(七)编写第一个C语言程序
- PHP九九乘法表
- openshift建立代理时SSH config文件的
- Swift基础(四)数组
- Error running test: Instant Run requires 'Tools | Android | Enable ADB integration' to be enabled.
- git 基本命令
- popupWindow使用详解+点击空白自动消失代码
- Sax解析XML
- Spring MVC 中 HandlerInterceptorAdapter的使用(转帖)
- com/android/dx/command/dexer/Main : Unsupported major.minor version 52.0
- 数据一致性模型
- PyCharm 2016.1.4 activation code
- CodeForces 686AFree Ice Cream
- hdu-3938-Portal-并查集