学习笔记: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)
$

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • ACM/ICPC2014鞍山现场赛E hdu5074Hatsune Miku「建议收藏」

    ACM/ICPC2014鞍山现场赛E hdu5074Hatsune Miku

  • 加多宝首度披露"换头手术"的详细内幕

    加多宝首度披露"换头手术"的详细内幕12月下旬,加多宝与王老吉的“改名案”和“怕上火案”判决结果先后出台,两大凉茶巨头之间的官司纠纷再起波澜。而加多宝集团品牌管理部负责人王月贵,在出席活动时首度披露了加多宝“换头手术”的详细内幕——由此,加多宝打赢凉茶之战的始末得以首次公开。以下为发言及访谈摘要:  快速出击,跟时间赛跑  在2012年,就在我们红罐凉茶迅速成长的时候,加多宝突然遭遇品牌地震,我们被迫放弃了使用和推广了17

    2022年10月29日
  • 卡巴斯基2月病毒及恶意软件排行榜

    卡巴斯基2月病毒及恶意软件排行榜互联网“热门”木马病毒排名下面显示了在2009年2月期间,中国地区的互联网上木马病毒的活跃情况。表中所列的都是最常遇到的恶意程序。这些恶意程序会在用户上网的同时给用户带来危害。(下表中的数据根据卡巴斯基产品检测情况统计得出)Nameofmalware % pp1. not-a-virus:AdWare.Win32.BHO.fay     7.69 +102. HEUR:Trojan…

  • Excel2JSON Excel转JSON Excel另存为JSON的技巧

    Excel2JSON Excel转JSON Excel另存为JSON的技巧不过欢迎大家转发到微博、微信、朋友圈~么么哒~JSON是码农们常用的数据格式,轻且方便,而直接手敲JSON却是比较麻烦和令人心情崩溃的(因为重复的东西很多),所以很多码农可能会和我一样,选择用Excel去输入数据,然后再想办法转换成JSON格式。小编今天推荐使用Excel直接另存为JSON的方法。该方法的特点是:除可以正常的直接按照表头作为key,内容作为value输出之外,还可以

  • 大数据ETL详解

    大数据ETL详解

    2021年10月28日
  • c++中条件运算符_单目运算符有哪些

    c++中条件运算符_单目运算符有哪些条件运算符是C++中唯一一个三元运算符,要求有三个操作对象,条件表达式的一般形式为:表达式1?表达式2:表达式3条件运算符的执行顺序是,先求解表达式1,若为真则求解表达式2,此时表达式2的值作为整个条件表达式的值。若表达式1的值为假,则求解表达式3,表达式3的值为整个条件表达式的值。max=(a>b)?a:ba比b大时,关系表达式为真,条件表达式的值为a;b比a大时,关系表达式为假,条件

发表回复

您的电子邮箱地址不会被公开。

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