学习笔记:04_Git的增、删、改和查看日志

学习笔记:04_Git的增、删、改和查看日志

使用git之前需要先配置user.nameuser.email

配置单的地方:

  • ~/.gitconfig –global
  • .git/config –local

which 命令


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ which vim
/usr/bin/vim

Administrator@kevin MINGW32 ~/desktop/myGit (master)

echo命令

$ echo 'hello git'
hello git

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ echo 'hello git 2' > a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 2
-rw-r--r-- 1 Administrator 197121 12 八月   21 20:18 a.txt
-rw-r--r-- 1 Administrator 197121 14 八月   20 22:24 test.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$

光标在前和后的快捷键:ctrl+A / ctrl+E

1.删除版本库的文件

git rm 文件名

$ git add a.txt
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   a.txt


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git commit -m '测试a.txt'
[master 807aa69] 测试a.txt
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
nothing to commit, working tree clean

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git rm a.txt
rm 'a.txt'

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ls
test.txt

staged 缓存区


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git reset HEAD a.txt  
Unstaged changes after reset:
D       a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    a.txt

no changes added to commit (use "git add" and/or "git commit -a")

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git checkout -- a.txt  // checkout -- :表示放弃前面的操作 reset Head 综合使用 才能把删除的文件恢复过来

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ls
a.txt  test.txt //删除的文件又回来的

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$

删除了文件不要提交,提交之后就不能进行恢复。

git rm


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git rm test.txt
rm 'test.txt'

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        deleted:    test.txt


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$
删除了一个文件,并且将删除的文件纳入到暂存区中(stage)
$ git commit -m 'delete test.txt'

如果想恢复删除的文件,需要有两个动作,

一个是:git reset HEAD test.txt

将删除的文件从缓存区恢复到工作区

另一个操作时候:git checkout – test.txt

rm

  test.txt之间删除掉了.这时候被删除的文件并未纳入暂存区当中。这个时候提交是不能的。

工作区—-缓存区—版本库

3.git重命名

git mv 移动重命名

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ echo 'h'>a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 2 八月   21 20:51 a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git mv a.txt b.txt
fatal: not under version control, source=a.txt, destination=b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 2 八月   21 20:51 a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git mv a.txt b.txt
fatal: not under version control, source=a.txt, destination=b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 2 八月   21 20:51 a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git mv a.txt b.txt
fatal: not under version control, source=a.txt, destination=b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        a.txt

nothing added to commit but untracked files present (use "git add" to track)

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git add a.txt
warning: LF will be replaced by CRLF in a.txt.
The file will have its original line endings in your working directory

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git commit
[master 79085b4] a.txt`
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git mv a.txt b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 2 八月   21 20:51 b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage) 
        renamed:    a.txt -> b.txt


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git restore --staged a.txt //从版本库到缓存区

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 1
-rw-r--r-- 1 Administrator 197121 2 八月   21 20:51 b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git checkout -- a.txt //从缓存区到工作区

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ ll
total 2
-rw-r--r-- 1 Administrator 197121 3 八月   21 20:54 a.txt
-rw-r--r-- 1 Administrator 197121 2 八月   21 20:51 b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ rm b.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ cat a.txt
h

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   b.txt

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    b.txt


Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git add a.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git commit -m 'git mv a.txt恢复'
[master 89acc6c] git mv a.txt恢复
 1 file changed, 1 insertion(+)
 create mode 100644 b.txt

git add . //点表示所有的文件包括当前文件下的子文件

git commit –amend -m ‘’ //上次提交的信息进行修正

4.git log

git log

  • -p 展开显示每次提交的内容差异
  • -n 仅显示最近的n次更新
  • –stat 仅显示简要的增改数统计
  • –pretty=oneline
  • –pretty=format:”%h – %an, %ar:%s”
$ git log --pretty=oneline
89acc6c51ca03c946dc5df3a544f052942ae72c2 (HEAD -> master) git mv a.txt恢复
79085b4ef43596322f78e7cf0c47943257f690ae a.txt`
05a4902d45a48933433a3a600bb9aa08690b8446 remove test.txt
f198cb6b4def9b5ebef319db5c09866a73bce97d delete a.txt
807aa691dc3d086530b8b36b5ad8a9ff91732b55 测试a.txt
9b79eb743639cfd7b6e62966d6012403ce3b3fd0 再次修改为 iloveyou to
ba82bafa862d0cccdd105e725f2e17f711a321eb 测试

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git log 3
fatal: ambiguous argument '3': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git log -3
commit 89acc6c51ca03c946dc5df3a544f052942ae72c2 (HEAD -> master)
Author: zx <xxx@qq.com>
Date:   Wed Aug 21 20:56:12 2019 +0800

    git mv a.txt恢复

commit 79085b4ef43596322f78e7cf0c47943257f690ae
Author: zx <xxx@qq.com>
Date:   Wed Aug 21 20:52:41 2019 +0800

    a.txt`

commit 05a4902d45a48933433a3a600bb9aa08690b8446
Author: zx <xxx@qq.com>
Date:   Wed Aug 21 20:41:52 2019 +0800

    remove test.txt

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$ git log --pretty=format:"%h - %an,%ar:%s"
89acc6c - zx,15 minutes ago:git mv a.txt恢复
79085b4 - zx,19 minutes ago:a.txt`
05a4902 - zx,29 minutes ago:remove test.txt
f198cb6 - zx,38 minutes ago:delete a.txt
807aa69 - zx,50 minutes ago:测试a.txt
9b79eb7 - zx,23 hours ago:再次修改为 iloveyou to
ba82baf - zx,23 hours ago:测试

Administrator@kevin MINGW32 ~/desktop/myGit (master)
$

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/100779.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Linux下netstat命令详解

    Linux下netstat命令详解一、介绍Netstat是控制台命令,是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。 二、输出信息描述执行netstat后输出如下:[root@sy-suz-srv51~]#netstatActiv…

    2022年5月7日
    42
  • 网站开发html_网页基础代码大全

    网站开发html_网页基础代码大全网页的标准是W3C,目前模式是HTML、CSS和JavaScript。HTML标签<!DOCTYPEHTML>是文档声明,必须写在HTML文档的第一行,位于<html>

    2022年8月2日
    2
  • app产品设计流程_APP流程图

    app产品设计流程_APP流程图App设计流程第一步、从APP产品需求入手,考虑我们到底要用什么主色调根据产品定位和目标用户群体选择主色调定好尺寸:设计尺寸是多大,是以640*1136设计还是750*1136还是1242*2208来设计。所有APP设计尺寸大小规范:http://www.25xt.com/appsize   第二步、配色和辅助色用什么颜色在考虑到产品气质和品牌色的同时,我们经常要考虑配合衬托产品主色调的辅助色…

    2022年8月30日
    2
  • HTTP 请求 报错信息406「建议收藏」

    背景:和APP(安卓)联调时,APP请求获取数据时提示406错误解决过程:在网上寻找资料(以前没遇到过),一一排除,最终解决(浪费蛮多时间所以记录下来,等待有缘人)。星空的阿斯的这篇博客https://blog.csdn.net/xingkongdeasi/article/details/799…

    2022年4月11日
    76
  • XMPP协议–自定义消息类型扩展

    XMPP协议–自定义消息类型扩展

    2021年8月11日
    53
  • 数据结构:栈和队列(Stack & Queue)【详解】

    数据结构:栈和队列(Stack & Queue)【详解】栈和队列知识框架栈一、栈的基本概念1、栈的定义栈(Stack):是只允许在一端进行插入或删除的线性表。首先栈是一种线性表,但限定这种线性表只能在某一端进行插入和删除操作。栈顶(Top):线性表允许进行插入删除的那一端。栈底(Bottom):固定的,不允许进行插入和删除的另一端。空栈:不含任何元素的空表。栈又称为先进先出(LastInFirstOut)的线性表,简称LIFO结构2、栈的基本操作InitStack(&S):初始化一个空栈S。StackEmpty(S):

    2022年5月5日
    80

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号