Git 基本操作1.md

$ pwd
/c/Users/Administrator
Administrator@YOUNG-PC MINGW64 ~
$ mkdir HelloWorld
Administrator@YOUNG-PC MINGW64 ~
$ cd HelloWorld/
Administrator@YOUNG-PC MINGW64 ~/HelloWorld
$ ls
Administrator@YOUNG-PC MINGW64 ~/HelloWorld
#初始化一个仓库,要进行版本管理,必须先初始化仓库
$ git init
Initialized empty Git repository in C:/Users/Administrator/HelloWorld/.git/

#执行完上面的命令后,下方提示的字符也发生了变化
$ ls -la
total 28
drwxr-xr-x 1 Administrator 197121 0 三月  9 12:03 ./
drwxr-xr-x 1 Administrator 197121 0 三月  9 12:03 ../
drwxr-xr-x 1 Administrator 197121 0 三月  9 12:03 .git/
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#这个文件下面的存储着管理当前目录所需的数据仓库
$ cd .git
Administrator@YOUNG-PC MINGW64 ~/HelloWorld/.git (GIT_DIR!)
$ ls
config  description  HEAD  hooks/  info/  objects/  refs/
Administrator@YOUNG-PC MINGW64 ~/HelloWorld/.git (GIT_DIR!)
# 这个地方不能用git命令,必须返回上一级目录
$ git status
fatal: This operation must be run in a work tree
Administrator@YOUNG-PC MINGW64 ~/HelloWorld/.git (GIT_DIR!)
$ cd ..
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ pwd
/c/Users/Administrator/HelloWorld
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ ls
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#查看仓库状态
$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ touch READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git status
On branch master
Initial commit
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        READM.md
nothing added to commit but untracked files present (use "git add" to track)
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#git add 想仓库中添加文件,下面的结果显示了我们再master分支下,如果只是单纯的创建了一个文件,并不会被加入git仓库的版本管理对象中,因此用git status 查看的话显示Untracked files,git add命令使之加入到缓存中,缓存是提交之前的一个临时区域

$ git add READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git status
On branch master
Initial commit
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)

#git commit 保存仓库的历史记录,,如果不加入-m,及后面的注释内容,则自动回出现vi编辑器,让你补充注释。
#终止提交 ,将提交信息留空,直接关闭编辑器,提交会自动终止。
$ git commit -m "Frist commit"
[master (root-commit) 05791aa] Frist commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)

#提交完成后查看,状态,说明已经提交了。
$ git commit
On branch master
nothing to commit, working directory clean
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#看下日志,记录了提交前后信息
$ git log
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date:   Wed Mar 9 20:06:28 2016 +0800
    Frist commit
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$
#优化显示信息

$ git log --pretty=short
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
    Frist commit
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)


#显示前后差别

$ git log -p
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date:   Wed Mar 9 20:06:28 2016 +0800
    Frist commit
diff --git a/READM.md b/READM.md
new file mode 100644
index 0000000..e69de29
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git log -p READM.md
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date:   Wed Mar 9 20:06:28 2016 +0800
    Frist commit
diff --git a/READM.md b/READM.md
new file mode 100644
index 0000000..e69de29
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)


#查看前后差别
$ vi READM.md
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git diff
diff --git a/READM.md b/READM.md
index e578ace..1e0b872 100644
--- a/READM.md
+++ b/READM.md
@@ -1 +1,2 @@
 hello world !
+#get some diff
warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)

查看工作数树和最新提交的差别

#如果不加入head,则啥也不会显示
$ git diff
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
#加入head后,可以看本次提交和上次提交之间的差别
$ git diff HEAD
diff --git a/READM.md b/READM.md
index e69de29..1e0b872 100644
--- a/READM.md
+++ b/READM.md
@@ -0,0 +1,2 @@
+hello world !
+#get some diff
warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$ git commit -m "Add index"
[master warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
478c9d6] Add index
warning: LF will be replaced by CRLF in READM.md.
The file will have its original line endings in your working directory.
 1 file changed, 2 insertions(+)
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)

#看下日志,查询到了第二个提交
$ git log
commit 478c9d6a50b3d44e3c57d534b899242e2dbc2a8a
Author: Thinker young <x695@qq.com>
Date:   Wed Mar 9 20:29:28 2016 +0800
    Add index
commit 05791aaa9acdcc8420ae8e61827ee1f41fbb45ff
Author: Thinker young <x695@qq.com>
Date:   Wed Mar 9 20:06:28 2016 +0800
    Frist commit
Administrator@YOUNG-PC MINGW64 ~/HelloWorld (master)
$
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贤时间

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值