如何跳过“git commit --amend"中的提交消息步骤? [英] How to skip the commit message step in "git commit --amend"?

查看:28
本文介绍了如何跳过“git commit --amend"中的提交消息步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个非常快速的代码-编译-测试循环,我经常修改提交的更改.

I'm running a very rapid code-compile-test loop where I am amending changes to my commits far more often than not.

例如:

# Make some changes
$ git commit -m "Added feature X"
# Compile, test
# Fix bugs
$ git commit -a --amend

我通常在修复错误后想要相同的提交消息.有没有办法让 git 跳过启动我的 EDITOR 而只使用原始提交消息?

I usually want the same commit message after I fix my bugs. Is there a way to make git skip firing up my EDITOR and just use the original commit message?

推荐答案

您只需添加 --no-edit 即可使用最后一条消息.此选项自 2005 年以来就存在,但直到最近才为 --amend 选项启用.

You can just add --no-edit to use the last message. This option existed since 2005 but only recently has been enabled for the --amend option.

另一种方法是将 -C HEAD 添加到带有修改选项的提交命令中.这使您不仅可以使用当前提交的消息,还可以指定任何其他您喜欢的引用,因此值得记住.

The other way is to add -C HEAD to the commit command with amend option. This allows you to not just use the current commit's message but you can specify any other reference you like, so it's worth remembering it.

这在从历史中的不同位置构建提交并使用这些提交的消息之一时特别有用.例如:

This is particularly useful when constructing a commit from various places in history and using one of those commit's messages. For example:

git checkout feature1^^ -- database/table1.sql
git checkout feature1^^^^ -- logger.py
git add -A && git commit -C feature1

这将只使用来自 feature1 的 2 次提交,并使用从最后一次提交到 feature1 的提交消息 - 如果这是一个很好的描述.

which would just use 2 commits from a feature1 and use the commit message from the last commit to feature1 - if that was a good description.

这篇关于如何跳过“git commit --amend"中的提交消息步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆