学习笔记: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)
上一篇 2021年7月11日 上午11:00
下一篇 2021年7月11日 下午12:00


相关推荐

  • windows环境下pycharm安装torch

    windows环境下pycharm安装torch环境为 windows python3 6 pycharm 经过 File gt settings gt gt 搜索框中搜索 torch 显示后尝试在 pycharm 中的 Terminal 中输入 pip3installh download pytorch org whl cu90 torch 1 1 0 cp36 cp36m win amd64 w

    2026年3月18日
    1
  • siamfc代码解读_SiamFC算法改进思路「建议收藏」

    siamfc代码解读_SiamFC算法改进思路「建议收藏」视频追踪问题中,目标通常是连续可微的。SiamFC利用全卷积孪生网络结构对搜索域和样本图像进行相似度匹配,实现追踪目标。本文分析了SiamFC在vot2015数据集上的追踪结果,总结出以下问题,并提出针对性的改进方案。表现鲁棒小范围晃动运动模糊短时局部遮挡重点问题光照变化视频中白色猫由亮处转入阴影中,跟踪结果开始出现偏差。光照条件较差,而且目标的衣服为黑色,与背景相似。特征不够明显。形变、尺度变换…

    2026年4月17日
    6
  • secureCRT乱码问题

    一、乱码如下:1、输入命令控制台乱码,如下图所示。二、解决方式:1、点击SercureCRT上排主菜单的“Options”,也就是“选项”菜单,如下图:2、点击【Options】之后,会出现一个下拉列表,我们选择第一个“SessionOptions…”,如下图所示。3、在弹出框中选择目录中的“Appearance”,该功能可以对SercureCRT的外观进行设置,如下图所示。4、S…

    2022年4月6日
    150
  • H264编码流程_h265和h265+视频编码有什么差别

    H264编码流程_h265和h265+视频编码有什么差别H264编码流程手绘图:H264编码网上图:

    2025年8月9日
    5
  • 歌词编辑软件哪个好_编歌词软件

    歌词编辑软件哪个好_编歌词软件https://www.cnblogs.com/BensonLaur/p/6262565.html 感谢开发这么好的工具!下载地址:http://beslyric.320.io/BesBlog/beslyric/download.action 文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言、评论转载于:https://www.cnblogs….

    2025年7月13日
    4
  • stm32f103波形发生器_示波器波形分析

    stm32f103波形发生器_示波器波形分析摘要本设计是基于STM32F103RCT6为主控核心的数字示波器的设计。包AD转换,波形处理,LCD液晶显示模块及外围按键,完成了简单的示波器功能,可以实时采样显示波形、振幅大小和…

    2022年10月15日
    8

发表回复

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

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