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


相关推荐

  • HotSpot的启动过程(配视频进行源码分析)

    HotSpot的启动过程(配视频进行源码分析)

    2020年11月20日
  • MFC的UDP编程实现[通俗易懂]

    MFC的UDP编程实现[通俗易懂]1、编程原理UDP是面向非连接的通信协议,比TCP协议简单很多。无论是服务器端还是客户端,其通信过程概括为:创建套接字(socket)–>绑定(bind)–>发送send(或接收recv)–>关闭套接字(closesocket) 2、特殊地址:在实际通信网络中,我们几乎不会用到“0.0.0.0″和“127.0.0.1”这样的IP地址。但是在一台计算机上,特别用于某些测试用

  • 怎么完全卸载赛门铁克_赛门铁克(sep)卸载方法

    怎么完全卸载赛门铁克_赛门铁克(sep)卸载方法卸载SEP(symantecendpointprotection),需要密码怎么办2011年12月08日下午1:50默认密码是symantec,或者Symantec1.点击“开始”->运行(或直接:Window徽标键+R)2.输入smc-stop终止SEP。如果跳出输入密码提示,则打开注册表(Window徽标键+R;输入regedit;敲回车),然后找到HKEY_LOCAL_MAC…

  • 跨境电商erp源码java大卖先生_java web项目源码和教程

    跨境电商erp源码java大卖先生_java web项目源码和教程语言:Java数据库:pgsql开发工具:IDEA源码类型:WebForm系统功能包括:订单管理、商品管理、采购管理、客服管理、库存管理、物流管理、报表统计、平台授权、系统管理等。

  • myeclipse6.5注册码

    myeclipse6.5注册码出处:http://www.cnblogs.com/qinqinmeiren/archive/2011/08/07/2151673.html做Java软件开发的,首选的软件工具莫非是MyEclipse

  • 百度地图api文档_奥维互动地图使用教程

    百度地图api文档_奥维互动地图使用教程新版百度地图API增加了发布版SHA1,开发版SHA1按官方教程操作即可,这里介绍一下发布版SHA1的获取方法。为apk签名,生成keystore文件(如果已经有keystore文件,跳过此步骤)打开cmd,定位文件夹到.andorid下,默认路径是users/用户名/.android输入keytool-list-v-keystore*.jks,*.jks为keystor

发表回复

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

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