Git提交更改文件记录
2221
在本文章教程中,我们将演示如何查看 Git 存储库的文件和提交文件记录,并对存储库中的文件作修改和提交。
在上一步中,我们已经修改了 main.py 文件中的代码,在代码中定义了两个变量并提交代码,但是要再次添加和修改main.py 文件中的代码,实现新功能:求两个变量相加值。修改提交的操作更改包含提交消息的最后一个提交; 它创建一个新的提交ID。
在修改操作之前,检查提交日志,如下命令所示:
$ git log commit d757c8e92ad6053db294100c77075865f829b7ac Author: your_name Date: Fri Jul 7 23:04:16 2017 +0800 define two var a & b 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
下面我们打开文件:main.py 加入以下两行:
c = a + b print("The value of c is ", c)
更正操作提交新的更改,并查看提交日志。首先查看状态,如下命令:
$ git status On branch master Your branch is ahead of 'origin/master' by 4 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 add main.py Administrator@MY-PC /D/worksp/sample (master) $ git status On branch master Your branch is ahead of 'origin/master' by 4 commits. (use "git push" to publish your local commits) Changes to be committed: (use "git reset HEAD ..." to unstage) modified: main.py
提交更改的文件,如下所示:
$ git commit --amend -m "add the sum of a & b " [master 51de0f0] add the sum of a & b 1 file changed, 5 insertions(+), 1 deletion(-)
现在,使用 git log命令显示将显示新的提交消息与新的提交ID(51de0f02eb48ed6b84a732512f230028d866b1ea),最近一次提交的放前面:
$ git log commit 51de0f02eb48ed6b84a732512f230028d866b1ea Author: your_name Date: Fri Jul 7 23:04:16 2017 +0800 add the sum of a & b 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
原文链接: https://www.yukx.com/github/article/details/1981.html 优科学习网Git提交更改文件记录
推荐文章
-
在IntelliJIDEA中,要根据数据库表直接生成对应的DataObject(DO)类,可以利用其内置的 DatabaseTools 功能,特别是其中的 JPABuddy插件 或者 ReverseEngineering(逆向工程) 功能。这里提供两种方法供您参考:方法一:使用JPABuddy插件J
-
说到分支管理模型,令人最为熟悉的莫过于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.12 Git提交更改文件记录