- Git基础概念
- Git历史(简史)
- Git基础和原理
- Git安装设置
- Git使用前配置
- Git快速入门
- Git工作流程
- Git创建存储库
- Git克隆操作
- Git执行变更操作
- Git查看更改
- Git提交更改
- Git推送(push)操作
- Git更新操作
- Git隐藏(Stash)操作
- Git移动操作
- Git重命名操作
- Git删除操作
- Git修正错误
- Git标签操作
- Git补丁操作
- Git管理分支
- Git处理冲突
- Git不同平台换行符问题
- Git远程操作详解
-
Git常用命令
- git config命令
- git help命令
- git init命令
- git add命令
- git clone命令
- git status命令
- git diff命令
- git commit命令
- git reset命令
- git rm命令
- git mv命令
- git branch命令
- git checkout命令
- git merge命令
- git mergetool命令
- git log命令
- git stash命令
- git tag命令
- git fetch命令
- git pull命令
- git push命令
- git remote命令
- git submodule命令
- git show命令
- git shortlog命令
- git describe命令
- git rebase命令
Git提交更改
在本文章教程中,我们将演示如何查看 Git 存储库的文件和提交文件记录,并对存储库中的文件作修改和提交。
注意:在开始学习本教程之前,先克隆一个存储库,有关如何克隆存储库,请参考: http://www.zyiz.net/git/git_clone_operation.html
在上一步中,我们已经修改了 main.py 文件中的代码,在代码中定义了两个变量并提交代码,但是要再次添加和修改main.py 文件中的代码,实现新功能:求两个变量相加值。修改提交的操作更改包含提交消息的最后一个提交; 它创建一个新的提交ID。
在修改操作之前,检查提交日志,如下命令所示 -
$ git log commit d757c8e92ad6053db294100c77075865f829b7ac Author: your_name <your_email@mail.com> Date: Fri Jul 7 23:04:16 2017 +0800 define two var a & b commit be24e214620fa072efa877e1967571731c465884 Author: your_name <your_email@mail.com> Date: Fri Jul 7 18:58:16 2017 +0800 ??mark commit 5eccf92e28eae94ec5fce7c687f6f92bf32a6a8d Author: your_name <your_email@mail.com> Date: Fri Jul 7 18:52:06 2017 +0800 this is main.py file commit mark use -m option commit 6e5f31067466795c522b01692871f202c26ff948 Author: your_name <your_email@mail.com> 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 <file>..." to update what will be committed) (use "git checkout -- <file>..." 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 <file>..." to unstage) modified: main.py
提交更改的文件,如下所示 -
$ git commit --amend -m "add the sum of a & b " [master 51de0f0] add the sum of a & b file changed, 5 insertions(+), 1 deletion(-)
现在,使用 git log
命令显示将显示新的提交消息与新的提交ID(51de0f02eb48ed6b84a732512f230028d866b1ea),最近一次提交的放前面:
$ git log commit 51de0f02eb48ed6b84a732512f230028d866b1ea Author: your_name <your_email@mail.com> Date: Fri Jul 7 23:04:16 2017 +0800 add the sum of a & b commit be24e214620fa072efa877e1967571731c465884 Author: your_name <your_email@mail.com> Date: Fri Jul 7 18:58:16 2017 +0800 ??mark commit 5eccf92e28eae94ec5fce7c687f6f92bf32a6a8d Author: your_name <your_email@mail.com> Date: Fri Jul 7 18:52:06 2017 +0800 this is main.py file commit mark use -m option commit 6e5f31067466795c522b01692871f202c26ff948 Author: your_name <your_email@mail.com> 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
上一篇:Git查看更改
下一篇:Git推送(push)操作