Git查看更改记录
2382
在本文章教程中,我们将演示如何查看 Git 存储库的文件和提交记录,并对存储库中的文件作修改和提交。
注意:在开始学习本教程之前,先克隆一个存储库,有关如何克隆存储库,请参考: Git克隆操作
比如,我们查看提交详细信息后,需要修改代码,或添加更多的代码,或者对比提交结果。
下面使用git log命令查看日志详细信息。
$ git log
执行上面命令后,得到以下输出结果:
$ git log commit be24e214620fa072efa877e1967571731c465884 Author: your_name Date: Fri Jul 7 18:58:16 2017 +0800 ??mark commit 5eccf92e28eae94ec5fce7c687f6f92bf32a6a8d Author: your_name Date: Fri Jul 7 18:52:06 2017 +0800 this is main.py file commit mark use -m option commit 6e5f31067466795c522b01692871f202c26ff948 Author: your_name Date: Fri Jul 7 18:42:43 2017 +0800 this is main.py file commit mark without use "-m" option commit 290342c270bc90f861ccc3d83afa920169e3b07e Author: Maxsu <769728683@qq.com> Date: Fri Jul 7 16:55:12 2017 +0800 Initial commit Administrator@MY-PC /D/worksp/sample (master) $
使用git show命令查看某一次提交详细信息。 git show命令采用SHA-1提交ID作为参数。
$ git show be24e214620fa072efa877e1967571731c465884 commit be24e214620fa072efa877e1967571731c465884 Author: your_name Date: Fri Jul 7 18:58:16 2017 +0800 ??mark diff --git a/main.py b/main.py index 91a1389..657c8d0 100644 --- a/main.py +++ b/main.py @@ -3,3 +3,5 @@ print ("Life is short, you need Python !") +# this is a comment line +
上面显示的结果中,可以看到符号 “+“ ,表示添加的内容。如果有 “-”则表示删除的内容,现在我们打开 main.py ,把注释行去掉并定义一个变量。修改后的 main.py 的内容如下所示:
#!/usr/bin/python3 #coding=utf-8 print ("Life is short, you need Python !") a = 10 b = 20
然后使用命令:git stauts 查看当前工作区状态:
$ git status On branch master Your branch is ahead of 'origin/master' by 3 commits. (use "git push" to publish your local commits) Changes not staged for commit: (use "git add ..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: main.py no changes added to commit (use "git add" and/or "git commit -a")
测试代码后,通过运行git diff命令来回顾他的更改。
$ git diff diff --git a/main.py b/main.py index 95053b4..a4f953e 100644 --- a/main.py +++ b/main.py @@ -4,4 +4,6 @@ print ("Life is short, you need Python !") -number = 100 +a = 10 + +b = 20
可以看到符号 “+“ (绿色),表示添加的内容。如果有 “-”(红色)则表示删除的内容。执行的效果如下所示:
现在使用以下命令将文件:main.py 添加到 git 暂存区,然后提交代码完成:
$ git add main.py $ git commit -m "define two var a & b "
最近修改的代码已提交完成。
原文链接: https://www.yukx.com/github/article/details/1980.html 优科学习网Git查看更改记录
推荐文章
-
说到分支管理模型,令人最为熟悉的莫过于TrunkBased和GitFlow。TrunkBased模型是持续集成思想所崇尚的工作方式,它由单个master分支和许多release分支组成,每个release分支在特定版本的提交点上从master分支创建出来,用来进行上线部署和Hotfix。在Trunk
-
在IntelliJIDEA(简称IDEA)中,如果你想避免导入星号(*)的方式引入包中的所有类,可以在设置中调整IDE的行为,使其遵循更严格的代码风格规范。虽然Java允许使用import*形式的静态导入(例如importstaticjava.util.Arrays.*;),但通常建议尽量明确导入所
-
随着软件开发项目越来越庞大,代码管理的难度也越来越大,特别是在团队协作中。Git作为目前最流行的代码版本控制工具之一,可以帮助我们高效地管理代码版本,并且很容易集成到团队的工作流中。在Git中,我们经常会遇到需要将新增的文件夹排除在Git的库之外的情况。这些文件夹可能是临时生成的文件夹、缓存文件夹或
-
1.迁移已有的Gitlab代码仓库存储目录gitlab通过rpm包安装后,默认存储位置在/var/opt/gitlab/git-data/repositories,通常需要更改此路径到单独的一个分区来存储仓库的数据。例如,我这里把数据存放到/data/gitlab目录下,创建/data/gitlab
-
编辑辑/etc/gitlab/gitlab.rb修改如下:external_url "http://gitlab.example.com"例如本人设置的如下:external_url 'http://gitlab.yukx.com'设置完成之后:重置配置sudo gitlab-ctl reconfi
-
什么是分支管理在版本控制过程中,使用多条线同时推进多个任务就是分支管理。如下图所示:分支管理的好处 ⒈同时并行推进多个功能开发,提高开发效率 ⒉各个分支在开发过程中,如果某一个分支开发失败,不会对其他分支有任何影响。失败的分支删除重新开始即可。 分支操作允许创建另一路线/方向上开发。我们可以使用这
学习大纲
1.11 Git查看更改记录