git commit --fixup hash 什么都不做
git commit --fixup hash does nothing
我有一个要修复的提交。我做错了什么?
git commit --fixup bdf55a7c12996e3af853c27ca4ff6c670e826c5e
On branch foo
nothing to commit, working tree clean
git --version
git version 2.31.0
您似乎认为 git commit --fixup
更改了现有提交。它没有。 git commit --fixup
和 git commit --squash
是改写历史的一部分,但它们只是解决方案的一部分。
git commit --fixup
不会更改您指向的提交。它在当前分支的头部创建一个新的提交,主题是从给定的提交构建的,前缀为 fixup!
。该提交是包含当前更改的常规提交,因此请使用 git add
或 git commit -a --fixup
添加和提交更改。
After that 运行 git rebase --interactive --autosquash
— 这是执行 fixup/squash 的主要命令。该命令对提交重新排序并向您显示 fixup/squash 的提交列表。验证列表并退出编辑器。 git rebase
将 运行 修复或压缩提交。
了解如何将所有内容组合在一个巧妙的别名中:https://blog.filippo.io/git-fixup-amending-an-older-commit/
[alias]
fixup = "!f() { TARGET=$(git rev-parse ""); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f"
要使用它:
git fixup bdf55a7c12996e3af853c27ca4ff6c670e826c5e
您在 中提到:
I didn't realize it wasn't meant for commit messages.
目前没有 git commit
选项 是 的意思。1 相反,您需要 运行 git rebase -i
(就像你通常所做的那样),然后将特定提交的 pick
行更改为 reword
行。
I still don't think I understand how to use the fixup tool correctly ...
这里要理解的是git commit --fixup
和git commit --squash
是比较晚的发明。 第一个 是git rebase --interactive
。 (还有更多的背景知识需要理解,但我们假设您通过重复的挑选准确地理解了 git rebase
的作用以及它是如何做到的。如果您不这样做,那就是一个单独的问题— 这已经在 Whosebug 上被询问和回答了,所以搜索那些问答。)
现在,由于 rebase 本质上是一系列的 cherry-pick 操作,我们观察到机械的、自动的、每次提交都按原样复制 rebase 有点无聊。我们添加了一些 兴奋!!! (在这里插入大片的爆炸声和巨响) 通过将一系列的 cherry-picks 变成命令块:
pick a123456 subject line from that commit
pick b789abc another commit subject line
pick cef0123 ... etc ...
pick d456789 and so on
然后,在完成此“指令 sheet”后,我们为您(用户)提供了 编辑 此指令 sheet 的机会。
例如,您可以更改 pick
行的 顺序 。这意味着不是按照原始顺序完成精选,而是按照您选择的新顺序完成。所以你可以重新洗牌 order 的提交。如果您有一个提交错误,并使用稍后的提交以某种方式修复它,您可以将错误和修复的提交并排放置!
到目前为止,这并没有多大帮助。你改变:
pick a123456 subject line from that commit
pick b789abc another commit subject line
pick cef0123 ... etc ...
pick d456789 and so on
pick eabcdef whoops
进入:
pick a123456 subject line from that commit
pick b789abc another commit subject line
pick eabcdef whoops
pick cef0123 ... etc ...
pick d456789 and so on
其中“whoops”提交修复了您在提交 b789abc
中犯下的错误。好的,所以如果你 运行 这些 指令,重新定位的结果是错误提交和修复提交现在 相邻 ,而不是由(的副本)分隔 cef0123
后跟 d456789
.
但现在我们添加了更多选项。例如,我们不只是 pick
,而是添加选项 squash
。这告诉 Git 不只是挑选提交 eabcdef
——修复早期提交的提交——它应该将 two 提交变成 单个组合提交。它还应该从两次提交中获取提交 日志消息,并将它们放入一个临时文件中,并将该临时文件用作提交消息... after 让您有机会编辑 该文件!
所以现在您可以将两个提交消息编辑成一个提交消息,用于将有缺陷的提交与其修复提交一起压缩所产生的组合提交!这就是最初的想法。
1正在为此添加一个新的提交选项。
让我们暂停一下,盘点一下
因此,使用只知道两个选项的交互式变基——pick
和 squash
——我们获得以下能力:
- 我们可以重新排序 提交,将密切相关的提交放在一起。
- 我们可以合并 提交。当我们这样做时,我们会被扔进我们的编辑器来为合并的提交编写正确的提交消息。
既然我们能做到这么多,让我们想想我们可能还想做些什么:
如果某些提交消息中有拼写错误,能够修复它会很好。
因此,对于我们现有的两个选项——pick
和 squash
——让我们添加一个 reword
选项。这将挑选提交,但也会让我们进入编辑器,让我们先更改提交消息。
如果提交中有错误,但我们已经修复了它并且我们不需要修复它的提交消息,它能够在损坏的提交之后立即进行修复提交会很好。我们已经可以通过移动它并使用 squash
来做到这一点。但这让我们陷入了我们的编辑器。最好只 keep 来自损坏提交的提交 message,同时压缩两个提交。
因此,对于我们现有的选项,让我们添加一个 fixup
选项。这将进行压缩,就像 squash
所做的那样,但 不会 将我们放入我们的编辑器中。它将 丢弃 修复提交的 消息 完全,在压缩修复时保留来自轻微损坏的提交的消息。
这些为我们提供了交互式变基可以执行的一些命令。在我们停止并声明我们的交互式 rebase 功能很漂亮并且应该成为 Git 的一部分之前,我们得到了更多(例如 edit
,它选择提交但随后停止,就好像存在冲突一样)并将其放入 Git 版本。然后它在 Git 中坐了几年。
现在几年过去了,我们说:嘿,如果我们可以 git commit
annotate 提交可能会很好,在我们完成它的时候,说它是一个压缩或修正提交 git rebase --interactive
应该自动变成 squash
或 rebase
. 这就是您遇到的情况。您在电影中来晚了,并不知道所有这些背景,但现在您已经阅读了一些剧透来解释电影的第一部分以及我们是如何走到这一步的。
这解释了为什么会出现错误:--fixup
提交应该修复 提交的文件 中的错误。它不是为了修复 提交消息 。目前还没有办法用 git commit
做到这一点。相反,您必须自己 运行 git rebase -i
,并将 pick
行更改为 reword
行。
随着 Git 2.32(2021 年第 2 季度),“git commit --fixup=<commit>
"(man) 已更改。
它是在保持原始日志消息完整的同时调整对内容所做的更改,但它现在已经学会了“--fixup=(amend|reword):<commit>
”,可用于调整消息和内容,并且仅消息,分别。
参见 commit 00ea64e, commit 8bedae4, commit 3d1bda6, commit 3270ae8, commit 494d314, commit 6e0e288 (15 Mar 2021) by Charvi Mendiratta (charvi-077
)。
(由 Junio C Hamano -- gitster
-- in commit 89519f6 合并,2021 年 3 月 26 日)
commit
: add amend suboption to --fixup to create amend! commit
Mentored-by: Christian Couder
Mentored-by: Phillip Wood
Helped-by: Junio C Hamano
Helped-by: Eric Sunshine
Signed-off-by: Charvi Mendiratta
git commit --fixup=amend:<commit>
"(man) will create an "amend!
" commit.
The resulting commit message subject will be "amend! ...
" where "...
" is the subject line of <commit>
and the initial message body will be <commit>
's message.
The "amend!
" commit when rebased with --autosquash
will fixup the contents and replace the commit message of <commit>
with the "amend!" commit's message body.
In order to prevent rebase from creating commits with an empty message we refuse to create an "amend!
" commit if commit message body is empty.
详情:
doc/git-commit
: add documentation for fixup=[amend|reword] options
Mentored-by: Christian Couder
Mentored-by: Phillip Wood
Helped-by: Eric Sunshine
Helped-by: Junio C Hamano
Signed-off-by: Eric Sunshine
Signed-off-by: Charvi Mendiratta
git commit
现在包含在其 man page 中:
[--dry-run] [(-c | -C | --squash) <commit> | --fixup [(amend|reword):]<commit>)]
git commit
现在包含在其 man page 中:
--fixup=[(amend|reword):]<commit>
Create a new commit which "fixes up" <commit>
when applied with
git rebase --autosquash
.
Plain --fixup=<commit>
creates a
"fixup!" commit which changes the content of <commit>
but leaves
its log message untouched.
--fixup=amend:<commit>
is similar but
creates an "amend!
" commit which also replaces the log message of
<commit>
with the log message of the "amend!
" commit.
--fixup=reword:<commit>
creates an "amend!
" commit which
replaces the log message of <commit>
with its own log message
but makes no changes to the content of <commit>
.
The commit created by plain --fixup=<commit>
has a subject
composed of "fixup!
" followed by the subject line from <commit>
,
and is recognized specially by git rebase --autosquash
.
The -m
option may be used to supplement the log message of the created
commit, but the additional commentary will be thrown away once the
"fixup!
" commit is squashed into <commit>
by
git rebase --autosquash
.
The commit created by --fixup=amend:<commit>
is similar but its
subject is instead prefixed with "amend!
".
The log message of <commit>
is copied into the log message of the "amend!
" commit and opened in an editor so it can be refined.
When git rebase --autosquash
squashes the "amend!
" commit into <commit>
, the
log message of <commit>
is replaced by the refined log message
from the "amend!
" commit.
It is an error for the "amend!
" commit's log message to be empty unless --allow-empty-message
is
specified.
--fixup=reword:<commit>
is shorthand for --fixup=amend:<commit> --only
.
It creates an "amend!
" commit with only a log message
(ignoring any changes staged in the index).
When squashed by git rebase --autosquash
, it replaces the log message of <commit>
without making any other changes.
Neither "fixup!
" nor "amend!
" commits change authorship of
<commit>
when applied by git rebase --autosquash
.
git rebase
现在包含在其 man page 中:
When the commit log message begins with "squash! ...
" or "fixup! ...
"
or "amend! ...
", and there is already a commit in the todo list that
matches the same ...
, automatically modify the todo list of
rebase -i
, so that the commit marked for squashing comes right after
the commit to be modified, and change the action of the moved commit
from pick
to squash
or fixup
or fixup -C
respectively.
A commit
matches the ...
if the commit subject matches, or if the ...
refers
to the commit's hash.
As a fall-back, partial matches of the commit
subject work, too.
The recommended way to create fixup/amend/squash
commits is by using the --fixup
, --fixup=amend:
or --fixup=reword:
and --squash
options respectively of git commit
.
随着 Git 2.34(2021 年第 4 季度),“git commit
"(man) --fixup
现在可以再次与 --edit
一起使用,在 v2 中被破坏后.32.
见commit 8ef6aad (14 Aug 2021) by Joel Klinghed (thejk
)。
(由 Junio C Hamano -- gitster
-- in commit 6e21f71 合并,2021 年 9 月 3 日)
commit
: restore --edit when combined with --fixup
Signed-off-by: Joel Klinghed
Recent changes to --fixup
, adding amend suboption, caused the --edit
flag to be ignored as use_editor
was always set to zero.
Restore edit_flag
having higher priority than fixup_message
when deciding the value of use_editor
by moving the edit flag condition later in the method.
我有一个要修复的提交。我做错了什么?
git commit --fixup bdf55a7c12996e3af853c27ca4ff6c670e826c5e
On branch foo
nothing to commit, working tree clean
git --version
git version 2.31.0
您似乎认为 git commit --fixup
更改了现有提交。它没有。 git commit --fixup
和 git commit --squash
是改写历史的一部分,但它们只是解决方案的一部分。
git commit --fixup
不会更改您指向的提交。它在当前分支的头部创建一个新的提交,主题是从给定的提交构建的,前缀为 fixup!
。该提交是包含当前更改的常规提交,因此请使用 git add
或 git commit -a --fixup
添加和提交更改。
After that 运行 git rebase --interactive --autosquash
— 这是执行 fixup/squash 的主要命令。该命令对提交重新排序并向您显示 fixup/squash 的提交列表。验证列表并退出编辑器。 git rebase
将 运行 修复或压缩提交。
了解如何将所有内容组合在一个巧妙的别名中:https://blog.filippo.io/git-fixup-amending-an-older-commit/
[alias]
fixup = "!f() { TARGET=$(git rev-parse ""); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f"
要使用它:
git fixup bdf55a7c12996e3af853c27ca4ff6c670e826c5e
您在
I didn't realize it wasn't meant for commit messages.
目前没有 git commit
选项 是 的意思。1 相反,您需要 运行 git rebase -i
(就像你通常所做的那样),然后将特定提交的 pick
行更改为 reword
行。
I still don't think I understand how to use the fixup tool correctly ...
这里要理解的是git commit --fixup
和git commit --squash
是比较晚的发明。 第一个 是git rebase --interactive
。 (还有更多的背景知识需要理解,但我们假设您通过重复的挑选准确地理解了 git rebase
的作用以及它是如何做到的。如果您不这样做,那就是一个单独的问题— 这已经在 Whosebug 上被询问和回答了,所以搜索那些问答。)
现在,由于 rebase 本质上是一系列的 cherry-pick 操作,我们观察到机械的、自动的、每次提交都按原样复制 rebase 有点无聊。我们添加了一些 兴奋!!! (在这里插入大片的爆炸声和巨响) 通过将一系列的 cherry-picks 变成命令块:
pick a123456 subject line from that commit
pick b789abc another commit subject line
pick cef0123 ... etc ...
pick d456789 and so on
然后,在完成此“指令 sheet”后,我们为您(用户)提供了 编辑 此指令 sheet 的机会。
例如,您可以更改 pick
行的 顺序 。这意味着不是按照原始顺序完成精选,而是按照您选择的新顺序完成。所以你可以重新洗牌 order 的提交。如果您有一个提交错误,并使用稍后的提交以某种方式修复它,您可以将错误和修复的提交并排放置!
到目前为止,这并没有多大帮助。你改变:
pick a123456 subject line from that commit
pick b789abc another commit subject line
pick cef0123 ... etc ...
pick d456789 and so on
pick eabcdef whoops
进入:
pick a123456 subject line from that commit
pick b789abc another commit subject line
pick eabcdef whoops
pick cef0123 ... etc ...
pick d456789 and so on
其中“whoops”提交修复了您在提交 b789abc
中犯下的错误。好的,所以如果你 运行 这些 指令,重新定位的结果是错误提交和修复提交现在 相邻 ,而不是由(的副本)分隔 cef0123
后跟 d456789
.
但现在我们添加了更多选项。例如,我们不只是 pick
,而是添加选项 squash
。这告诉 Git 不只是挑选提交 eabcdef
——修复早期提交的提交——它应该将 two 提交变成 单个组合提交。它还应该从两次提交中获取提交 日志消息,并将它们放入一个临时文件中,并将该临时文件用作提交消息... after 让您有机会编辑 该文件!
所以现在您可以将两个提交消息编辑成一个提交消息,用于将有缺陷的提交与其修复提交一起压缩所产生的组合提交!这就是最初的想法。
1正在为此添加一个新的提交选项。
让我们暂停一下,盘点一下
因此,使用只知道两个选项的交互式变基——pick
和 squash
——我们获得以下能力:
- 我们可以重新排序 提交,将密切相关的提交放在一起。
- 我们可以合并 提交。当我们这样做时,我们会被扔进我们的编辑器来为合并的提交编写正确的提交消息。
既然我们能做到这么多,让我们想想我们可能还想做些什么:
如果某些提交消息中有拼写错误,能够修复它会很好。
因此,对于我们现有的两个选项——
pick
和squash
——让我们添加一个reword
选项。这将挑选提交,但也会让我们进入编辑器,让我们先更改提交消息。如果提交中有错误,但我们已经修复了它并且我们不需要修复它的提交消息,它能够在损坏的提交之后立即进行修复提交会很好。我们已经可以通过移动它并使用
squash
来做到这一点。但这让我们陷入了我们的编辑器。最好只 keep 来自损坏提交的提交 message,同时压缩两个提交。因此,对于我们现有的选项,让我们添加一个
fixup
选项。这将进行压缩,就像squash
所做的那样,但 不会 将我们放入我们的编辑器中。它将 丢弃 修复提交的 消息 完全,在压缩修复时保留来自轻微损坏的提交的消息。
这些为我们提供了交互式变基可以执行的一些命令。在我们停止并声明我们的交互式 rebase 功能很漂亮并且应该成为 Git 的一部分之前,我们得到了更多(例如 edit
,它选择提交但随后停止,就好像存在冲突一样)并将其放入 Git 版本。然后它在 Git 中坐了几年。
现在几年过去了,我们说:嘿,如果我们可以 git commit
annotate 提交可能会很好,在我们完成它的时候,说它是一个压缩或修正提交 git rebase --interactive
应该自动变成 squash
或 rebase
. 这就是您遇到的情况。您在电影中来晚了,并不知道所有这些背景,但现在您已经阅读了一些剧透来解释电影的第一部分以及我们是如何走到这一步的。
这解释了为什么会出现错误:--fixup
提交应该修复 提交的文件 中的错误。它不是为了修复 提交消息 。目前还没有办法用 git commit
做到这一点。相反,您必须自己 运行 git rebase -i
,并将 pick
行更改为 reword
行。
随着 Git 2.32(2021 年第 2 季度),“git commit --fixup=<commit>
"(man) 已更改。
它是在保持原始日志消息完整的同时调整对内容所做的更改,但它现在已经学会了“--fixup=(amend|reword):<commit>
”,可用于调整消息和内容,并且仅消息,分别。
参见 commit 00ea64e, commit 8bedae4, commit 3d1bda6, commit 3270ae8, commit 494d314, commit 6e0e288 (15 Mar 2021) by Charvi Mendiratta (charvi-077
)。
(由 Junio C Hamano -- gitster
-- in commit 89519f6 合并,2021 年 3 月 26 日)
commit
: add amend suboption to --fixup to create amend! commitMentored-by: Christian Couder
Mentored-by: Phillip Wood
Helped-by: Junio C Hamano
Helped-by: Eric Sunshine
Signed-off-by: Charvi Mendiratta
git commit --fixup=amend:<commit>
"(man) will create an "amend!
" commit.
The resulting commit message subject will be "amend! ...
" where "...
" is the subject line of<commit>
and the initial message body will be<commit>
's message.The "
amend!
" commit when rebased with--autosquash
will fixup the contents and replace the commit message of<commit>
with the "amend!" commit's message body.In order to prevent rebase from creating commits with an empty message we refuse to create an "
amend!
" commit if commit message body is empty.
详情:
doc/git-commit
: add documentation forfixup=[amend|reword] options
Mentored-by: Christian Couder
Mentored-by: Phillip Wood
Helped-by: Eric Sunshine
Helped-by: Junio C Hamano
Signed-off-by: Eric Sunshine
Signed-off-by: Charvi Mendiratta
git commit
现在包含在其 man page 中:
[--dry-run] [(-c | -C | --squash) <commit> | --fixup [(amend|reword):]<commit>)]
git commit
现在包含在其 man page 中:
--fixup=[(amend|reword):]<commit>
Create a new commit which "fixes up"
<commit>
when applied withgit rebase --autosquash
.Plain
--fixup=<commit>
creates a "fixup!" commit which changes the content of<commit>
but leaves its log message untouched.
--fixup=amend:<commit>
is similar but creates an "amend!
" commit which also replaces the log message of<commit>
with the log message of the "amend!
" commit.
--fixup=reword:<commit>
creates an "amend!
" commit which replaces the log message of<commit>
with its own log message but makes no changes to the content of<commit>
.The commit created by plain
--fixup=<commit>
has a subject composed of "fixup!
" followed by the subject line from<commit>
, and is recognized specially bygit rebase --autosquash
.
The-m
option may be used to supplement the log message of the created commit, but the additional commentary will be thrown away once the "fixup!
" commit is squashed into<commit>
bygit rebase --autosquash
.The commit created by
--fixup=amend:<commit>
is similar but its subject is instead prefixed with "amend!
".
The log message of<commit>
is copied into the log message of the "amend!
" commit and opened in an editor so it can be refined.
Whengit rebase --autosquash
squashes the "amend!
" commit into<commit>
, the log message of<commit>
is replaced by the refined log message from the "amend!
" commit.It is an error for the "
amend!
" commit's log message to be empty unless--allow-empty-message
is specified.
--fixup=reword:<commit>
is shorthand for--fixup=amend:<commit> --only
.
It creates an "amend!
" commit with only a log message (ignoring any changes staged in the index).
When squashed bygit rebase --autosquash
, it replaces the log message of<commit>
without making any other changes.Neither "
fixup!
" nor "amend!
" commits change authorship of<commit>
when applied bygit rebase --autosquash
.
git rebase
现在包含在其 man page 中:
When the commit log message begins with "
squash! ...
" or "fixup! ...
" or "amend! ...
", and there is already a commit in the todo list that matches the same...
, automatically modify the todo list ofrebase -i
, so that the commit marked for squashing comes right after the commit to be modified, and change the action of the moved commit frompick
tosquash
orfixup
orfixup -C
respectively.A commit matches the
...
if the commit subject matches, or if the...
refers to the commit's hash.As a fall-back, partial matches of the commit subject work, too.
The recommended way to create fixup/amend/squash commits is by using the
--fixup
,--fixup=amend:
or--fixup=reword:
and--squash
options respectively ofgit commit
.
随着 Git 2.34(2021 年第 4 季度),“git commit
"(man) --fixup
现在可以再次与 --edit
一起使用,在 v2 中被破坏后.32.
见commit 8ef6aad (14 Aug 2021) by Joel Klinghed (thejk
)。
(由 Junio C Hamano -- gitster
-- in commit 6e21f71 合并,2021 年 9 月 3 日)
commit
: restore --edit when combined with --fixupSigned-off-by: Joel Klinghed
Recent changes to
--fixup
, adding amend suboption, caused the--edit
flag to be ignored asuse_editor
was always set to zero.Restore
edit_flag
having higher priority thanfixup_message
when deciding the value ofuse_editor
by moving the edit flag condition later in the method.