Git 笔记 - git commit_小晗同学的博客-程序员宝宝

技术标签: github  Git  git  git commit  

01 git commit

如果没有设置 -m 选项,直接运行 git commit 会出现什么情况呢?

答案是: Git 会尝试为你打开一个编辑器以填写提交信息。 如果 Git 在你对它的配置中找不到相关信息,默认会打开 vim。如下图:
commit0
接下来,需要键盘敲 i 进入编辑模式,而后在第一行,即红色区域部分填写提交信息:
commit1
信息编辑好之后按 ESC,键盘敲 :wq ,即保存并退出:
commit2
最后你会看到控制台的返回消息:

$ git add .
$ git commit
[master 1bbbda5] init hello
 1 file changed, 1 insertion(+)
 create mode 100644 hello.js

02 git commit -m

 # 方式 1
 git commit -m <msg>
 # 方式 2
 git commit --message=<msg>

描述 :使用给定 msg 作为提交消息,即 Git 就不会打开编辑器了,也就省略了上面的步骤了。

注意-m-c -C -F 是相互排斥的!

03 git commit -a

 # 方式 1
 git commit -a
 # 方式 2
 git commit --all

描述 :修改文件后不需要执行 git add 命令,直接就可以提交。

注意 :新建的文件除外!

04 git commit -p

 # 方式 1
 git commit -p
 # 方式 2
 git commit --patch

描述 :使用交互式界面来选择要提交的更改,让用户有机会在将修改后的内容提交前查看差异。

使用示范

$ git commit -p
diff --git a/hello.js b/hello.js
index 2ccb4c8..31b09bc 100644
--- a/hello.js
+++ b/hello.js
@@ -1,2 +1,3 @@     # ----这里会显示你的修改----
-let hello = 1;     # ----这里会显示你的修改----
+let hello = 123;
 let world = 456;
+let people = 789;  # ----这里会显示你的修改----
(1/1) Stage this hunk [y,n,q,a,d,e,?]?  # 此处需要输入你想要执行的操作
# --------- 下面是每个选项的意思 ---------- 
y - stage this hunk
n - do not stage this hunk
q - quit; do not stage this hunk or any of the remaining ones
a - stage this hunk and all later hunks in the file
d - do not stage this hunk or any of the later hunks in the file
e - manually edit the current hunk
? - print help
# --------- 上面是每个选项的意思 ---------- 

05 git commit -C

 # 方式 1
 git commit -C
 # 方式 2
 git commit --reuse-message=<commit>

描述 :获取现有的提交对象 commitId ,并在创建提交时重用日志消息和作者信息(包括时间戳)。换句话说就是重新使用之前提交过的信息去提交新的更改。

使用示范

# 先查看重用信息的 commitId
$ git log
commit aa63767da23f357136333b7ce18175c414b189ec (HEAD -> master)
Author: xxxxxx<xxxxxx.com>
Date:   Mon Oct 25 16:30:41 2021 +0800

    change hello
    
commit fcadef453058fb4b97b7c0cbc2994bed3a81302e
Author: xxxxxx<xxxxxx.com>
Date:   Mon Oct 25 16:30:06 2021 +0800

    init
    
# 举例:重用 init 的提交信息
$ git commit -C fcadef453058fb4b97b7c0cbc2994bed3a81302e
[master e82bdf2] init
 Date: Mon Oct 25 16:30:06 2021 +0800
 1 file changed, 1 insertion(+), 1 deletion(-)

结果如下:(作者,时间和信息都是一样的噢)
commitC

06 git commit -c

 # 方式 1
 git commit -c
 # 方式 2
 git commit --reedit-message=<commit>

描述 :与 -C 类似,但使用 -c 会调用编辑器,以便用户可以进一步编辑提交消息,即与 -C 相比多了一项修改编辑的步骤。

07 git commit -n

 # 方式 1
 git commit -n
 # 方式 2
 git commit --no-verify

描述 :这个选项可以绕过 pre-commitcommit-msg

08 git commit --amend

描述 :通过创建新提交来替换当前分支的提交信息。

使用示范 1 :修改上一次的提交信息。

# 查看最新的提交信息
$ git log   
commit 155f771f90997b88dd71d4952dee3cf15618af1b (HEAD -> master)
Author: xxxxxx<xxxxxx.com>
Date:   Mon Oct 25 17:15:08 2021 +0800

    edit test

commit 69322b677a3a6be363ba559610988607480677ce
Author: xxxxxx<xxxxxx.com>
Date:   Mon Oct 25 17:11:30 2021 +0800

    init

# 举例:将 edit test 提交信息修改为 modify test

执行命令 git commit --amend ,会出现下面的编辑界面,将红色框选区中修改为想要的信息:
在这里插入图片描述
结果预览:修改之后查看提交记录,发现提交信息已经按照预期进行了修改,同时需要注意 commitId 也发生了变化。
在这里插入图片描述

使用示范 2 :将最近的修改追加到上一次的提交上。

# 查看最新的提交信息
$ git log           
commit 6681933eee000dcb99acc18f6c0fb246c551a7ad (HEAD -> master)
Author: xxxxxx<xxxxxx.com>
Date:   Mon Oct 25 17:15:08 2021 +0800

    modify test

commit 69322b677a3a6be363ba559610988607480677ce
Author: xxxxxx<xxxxxx.com>
Date:   Mon Oct 25 17:11:30 2021 +0800

    init

# 查看当前文件状态
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   test.js

no changes added to commit (use "git add" and/or "git commit -a")

# 暂存文件
$ git add .

# 将修改追加到上一次提交
$ git commit --amend

# 如果需要修改提交信息,则可以在出现编辑界面时进行修改;
# 若想保持上次提交信息,则直接退出 :q 编辑界面;
# ------------- 下面是编辑器显示内容------------
modify test

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Oct 25 17:15:08 2021 +0800
#
# On branch master
# Changes to be committed:
#       modified:   test.js
#
~                                                                                                                                                                  
~                                                                                                                                                                  
~                                                                                                                                                                  
"~/Documents/code/test/.git/COMMIT_EDITMSG" 11L, 266B
# ------------- 上面是编辑器显示内容------------

结果预览:追加提交完成, commitId 也发生了变化。
在这里插入图片描述

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Yuki_yuhan/article/details/120934822

智能推荐

大数据技术之Hadoop(HDFS)_hdfs技术_花花叔叔的博客-程序员宝宝

HDFS简介HDFS的Shell操作 HDFS的写数据流程网络拓扑- 节点距离计算机架感知HDFS的读数据流程NN 和 和 2NN 工作机制DataNode工作机制

线性规划专题——Lingo的使用_lingo中的subjectto怎么使用_Icoding_F2014的博客-程序员宝宝

虽然,经过前面的讲解,我们会实现单纯形法了,但是很多时候我们最好还是借助于工具来进行线性规划 尤其是 整数规划的时候。安装https://www.lindo.com/index.php/ls-downloads/try-lingo下载安装使用在编辑框输入目标函数和约束条件然后再点击Solver-solve。Lingo的写法:1.目标函数 max,min2.约束:以s.t....

DIDL-Lite_RationalGo的博客-程序员宝宝

digital item declaration language (DIDL-Lite): A subset of the Digital Item Declaration Language (DIDL), which is an XML dialect developed within ISO/MPEG21 [MPEG-21].数字项描述语言的一个子集。

android源码分析-aapt_whf727的博客-程序员宝宝

aapt就是Android Asset Packaging Tool ,一般在sdk的tools中可以找到,一般是和adb之类的工具在一起。这个工具可以查看, 创建, 更新ZIP格式的文档附件(zip, jar, apk)。 也可将资源文件编译成二进制文件。    android的核心代码还没有来得及看呢,这篇我主要是讲述这几天将linux上面的这块代码一直到windows上面的经验。aapt

vue+vant实现购物车全选、单个删除功能_风xiansheng的博客-程序员宝宝

vue+vant实现购物车全选、单个删除功能效果展示一、html代码&lt;div class="cart"&gt; &lt;ul class="cart-list"&gt; &lt;li class="goods" v-for="(item, index) in cartList" :key="item._id + index" &gt; &lt;!-- checked是自己添加 --&gt;

色彩转换系列之RGB格式与HSI格式互转原理及实现_rgb转化hsi_小武~~的博客-程序员宝宝

写在前面HSI色彩空间是从人的视觉系统出发,直接用颜色三要素:色调(Hue)、饱和度(Saturation或Chroma)和亮度 (Intensity或Brightness)来描述色彩。H——表示颜色的相位角,是彩色最重要的属性,决定颜色的本质。红、绿、蓝分别相隔120度;互补色分别相差180度,即颜色的类别。 S——表示颜色的深浅程度,饱和度越高,颜色越深。与白色的比例有关,白色比例...

随便推点

conda环境常用命令_conda进入环境的命令_矮矮的夏祭的博客-程序员宝宝

在不同的项目中经常需要conda来配置环境,这样能够实现不同版本的python和库的随意切换,并且减少了很多不必要的麻烦。这里记录下conda常用的一些基础命令,以便后续查询

Nucleus参考(一)_zhengyongchen的博客-程序员宝宝

Introduction A  task  is  a  semi-independent  program  segment with  a  dedicated  purpose.  Most modern real-time applications require multiple tasks. Additionally, these tasks often have varying de

Unity接入GME游戏多媒体引擎_小菜希的博客-程序员宝宝

离线语音课参考文章https://blog.csdn.net/cyf649669121/article/details/85246017官网文档https://cloud.tencent.com/document/product/607/15228官方SDK和demo下载网址https://cloud.tencent.com/document/product/607/18521如果麦克...

echarts仪表盘不靠边的解决办法_echarts仪表盘居中_越来越好。的博客-程序员宝宝

echarts仪表盘不靠边的解决办法仪表盘中,默认图表是水平垂直居中,如果要改外边距,用grid是不行的, 要用 center , center:['50%','50%'],第一个左,第二个上 一个整圆,要加起来小于等于359.9度,如果整360度,则开始点和结束点会重合。 series: [ { name: '外...

Sagheer and Nubian Market CodeForces - 812C (二分)_weixin_30265171的博客-程序员宝宝

On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It containsndifferent items numbered from1to...

Windbg+Procdump解决w3wp.exe CPU过百问题_weixin_30838873的博客-程序员宝宝

最近发布在windows server2012 IIS8.0上的一个WebAPI项目,才几十个人在线,CPU就会出现过百情况,并且CPU一旦过百应用程序池就自动暂停掉,看到这个问题我感觉应该是程序哪个地方出了问题, 8盒16G 应该配置还是可以的。打算使用windbg找到这个问题。为了快速定位问题我就直接在生产环境安装了windbg,为了采集dump文件,我选择Procdu...

推荐文章

热门文章

相关标签